Skip to content

Commit

Permalink
rm unused
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxbin committed Oct 21, 2020
1 parent d2262b5 commit f104225
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 50 deletions.
3 changes: 0 additions & 3 deletions core/consensus/common/src/block_import.rs
Expand Up @@ -202,9 +202,6 @@ pub trait JustificationImport<B: BlockT> {
/// Called by the import queue when it is started.
fn on_start(&self, _link: &crate::import_queue::Link<B>) { }

/// Called by the import queue when it is periodic tick.
fn on_tick(&self, _link: &crate::import_queue::Link<B>) { }

/// Import a Block justification and finalize the given block.
fn import_justification(
&self,
Expand Down
26 changes: 6 additions & 20 deletions core/consensus/common/src/import_queue.rs
Expand Up @@ -52,9 +52,6 @@ pub type SharedJustificationImport<B> = Arc<dyn JustificationImport<B, Error=Con
/// Maps to the Origin used by the network.
pub type Origin = libp2p::PeerId;

/// Interval at which we perform time based maintenance
const TICK_TIMEOUT: time::Duration = time::Duration::from_millis(1000);

/// Block data used by the queue.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct IncomingBlock<B: BlockT> {
Expand Down Expand Up @@ -210,7 +207,6 @@ pub enum BlockImportMsg<B: BlockT> {
ImportBlocks(BlockOrigin, Vec<IncomingBlock<B>>),
ImportJustification(Origin, B::Hash, NumberFor<B>, Justification),
Start(Box<Link<B>>, Sender<Result<(), std::io::Error>>),
Tick,
Stop,
#[cfg(any(test, feature = "test-helpers"))]
Synchronize,
Expand Down Expand Up @@ -261,16 +257,15 @@ impl<B: BlockT> BlockImporter<B> {
link: None,
justification_import,
};
let tick_timeout = channel::tick(TICK_TIMEOUT);
while importer.run(&tick_timeout) {
while importer.run() {
// Importing until all senders have been dropped...
}
})
.expect("ImportQueue thread spawning failed");
sender
}

fn run(&mut self, tick_timeout: &Receiver<time::Instant>) -> bool {
fn run(&mut self) -> bool {
let msg = select! {
recv(self.port) -> msg => {
match msg {
Expand All @@ -284,10 +279,7 @@ impl<B: BlockT> BlockImporter<B> {
Err(_) => unreachable!("1. We hold a sender to the Worker, 2. it should not quit until that sender is dropped; qed"),
Ok(msg) => ImportMsgType::FromWorker(msg),
}
},
recv(tick_timeout) -> _ => {
ImportMsgType::FromNetwork(BlockImportMsg::Tick)
},
}
};
match msg {
ImportMsgType::FromNetwork(msg) => self.handle_network_msg(msg),
Expand All @@ -310,12 +302,6 @@ impl<B: BlockT> BlockImporter<B> {
self.link = Some(link);
let _ = sender.send(Ok(()));
},
BlockImportMsg::Tick => {
if let Some(justification_import) = self.justification_import.as_ref() {
let link = self.link.as_ref().expect("qed");
justification_import.on_tick(&**link);
}
},
BlockImportMsg::Stop => return false,
#[cfg(any(test, feature = "test-helpers"))]
BlockImportMsg::Synchronize => {
Expand Down Expand Up @@ -370,7 +356,7 @@ impl<B: BlockT> BlockImporter<B> {

if aux.needs_justification {
trace!(target: "sync", "Block imported but requires justification {}: {:?}", number, hash);
link.request_justification(&hash, number, false);
link.request_justification(&hash, number);
}

if aux.bad_justification {
Expand Down Expand Up @@ -537,7 +523,7 @@ pub trait Link<B: BlockT>: Send {
/// Clear all pending justification requests.
fn clear_justification_requests(&self) {}
/// Request a justification for the given block.
fn request_justification(&self, _hash: &B::Hash, _number: NumberFor<B>, _force: bool) {}
fn request_justification(&self, _hash: &B::Hash, _number: NumberFor<B>) {}
/// Disconnect from peer.
fn useless_peer(&self, _who: Origin, _reason: &str) {}
/// Disconnect from peer and restart sync.
Expand Down Expand Up @@ -630,7 +616,7 @@ pub fn import_single_block<B: BlockT, V: Verifier<B>>(
}
};

match import_error(import_handle.check_block(hash, number,parent))? {
match import_error(import_handle.check_block(hash, number, parent))? {
BlockImportResult::ImportedUnknown { .. } => (),
r @ _ => return Ok(r), // Any other successfull result means that the block is already imported.
}
Expand Down
2 changes: 1 addition & 1 deletion core/finality-grandpa/src/import.rs
Expand Up @@ -97,7 +97,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA> JustificationImport<Block>
if let Ok(Some(hash)) = effective_block_hash {
if let Ok(Some(header)) = self.inner.header(&BlockId::Hash(hash)) {
if *header.number() == pending_change.effective_number() {
link.request_justification(&header.hash(), *header.number(), false);
link.request_justification(&header.hash(), *header.number());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/network/src/protocol.rs
Expand Up @@ -244,7 +244,7 @@ pub enum ProtocolMsg<B: BlockT, S: NetworkSpecialization<B>> {
/// Tell protocol to clear all pending justification requests.
ClearJustificationRequests,
/// Tell protocol to request justification for a block.
RequestJustification(B::Hash, NumberFor<B>, bool),
RequestJustification(B::Hash, NumberFor<B>),
/// Inform protocol whether a justification was successfully imported.
JustificationImportResult(B::Hash, NumberFor<B>, bool),
/// Propagate a block to peers.
Expand Down Expand Up @@ -428,10 +428,10 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
ProtocolMsg::AnnounceBlock(hash) => self.announce_block(hash),
ProtocolMsg::BlockImportedSync(hash, number) => self.sync.block_imported(&hash, number),
ProtocolMsg::ClearJustificationRequests => self.sync.clear_justification_requests(),
ProtocolMsg::RequestJustification(hash, number, force) => {
ProtocolMsg::RequestJustification(hash, number) => {
let mut context =
ProtocolContext::new(&mut self.context_data, &self.network_chan);
self.sync.request_justification(&hash, number, &mut context, force);
self.sync.request_justification(&hash, number, &mut context);
},
ProtocolMsg::JustificationImportResult(hash, number, success) => {
let mut context =
Expand Down
4 changes: 2 additions & 2 deletions core/network/src/service.rs
Expand Up @@ -108,8 +108,8 @@ impl<B: BlockT, S: NetworkSpecialization<B>> Link<B> for NetworkLink<B, S> {
let _ = self.protocol_sender.send(ProtocolMsg::ClearJustificationRequests);
}

fn request_justification(&self, hash: &B::Hash, number: NumberFor<B>, force: bool) {
let _ = self.protocol_sender.send(ProtocolMsg::RequestJustification(hash.clone(), number, force));
fn request_justification(&self, hash: &B::Hash, number: NumberFor<B>) {
let _ = self.protocol_sender.send(ProtocolMsg::RequestJustification(hash.clone(), number));
}

fn useless_peer(&self, who: PeerId, reason: &str) {
Expand Down
22 changes: 1 addition & 21 deletions core/network/src/sync.rs
Expand Up @@ -252,7 +252,6 @@ impl<B: BlockT> PendingJustifications<B> {
&mut self,
justification: &PendingJustification<B>,
is_descendent_of: F,
force: bool,
) where F: Fn(&B::Hash, &B::Hash) -> Result<bool, ClientError> {
trace!(target: "sync", "Queue justification request: hash: {} number: {} justifications_finalized: {:?}", justification.0.clone(), justification.1.clone(), self.justifications.best_finalized_number);

Expand All @@ -267,24 +266,6 @@ impl<B: BlockT> PendingJustifications<B> {
justification.1,
err,
);

if force {
let in_root = self.justifications.roots().find(|(&hash, &number, data)| {
justification.0 == hash && justification.1 == number
}).is_some();
if in_root {
let in_pending = self.pending_requests.contains(&justification);
let in_peer = self.peer_requests.iter().find(|(_, (j, _))| {
justification == j
}).is_some();

info!(target: "sync", "Force queueing request: {:?}, in_pending: {}, in_peer: {}", justification, in_pending, in_peer);
if !in_pending && !in_peer {
self.pending_requests.push_back((justification.0, justification.1));
}
}
}

return;
},
_ => {},
Expand Down Expand Up @@ -893,12 +874,11 @@ impl<B: BlockT> ChainSync<B> {
/// Request a justification for the given block.
///
/// Queues a new justification request and tries to dispatch all pending requests.
pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut Context<B>, force: bool) {
pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut Context<B>) {
trace!(target: "sync", "Request justification: number: {}, hash: {}", number, hash);
self.justifications.queue_request(
&(*hash, number),
|base, block| protocol.client().is_descendent_of(base, block),
force,
);

self.justifications.dispatch(&mut self.peers, protocol, &*self.import_queue);
Expand Down

0 comments on commit f104225

Please sign in to comment.