diff --git a/ethcore/light/src/net/mod.rs b/ethcore/light/src/net/mod.rs index 08bd3347d..464c71fbe 100644 --- a/ethcore/light/src/net/mod.rs +++ b/ethcore/light/src/net/mod.rs @@ -284,8 +284,8 @@ impl LightProtocol { let peer = try!(peers.get(peer_id).ok_or_else(|| Error::UnknownPeer)); let mut peer = peer.lock(); - match peer.remote_flow.as_mut() { - Some(&mut (ref mut buf, ref flow)) => { + match peer.remote_flow { + Some((ref mut buf, ref flow)) => { flow.recharge(buf); let max = flow.compute_cost(request.kind(), request.amount()); try!(buf.deduct_cost(max)); @@ -296,6 +296,8 @@ impl LightProtocol { let req_id = self.req_id.fetch_add(1, Ordering::SeqCst); let packet_data = encode_request(&request, req_id); + trace!(target: "les", "Dispatching request {} to peer {}", req_id, peer_id); + let packet_id = match request.kind() { request::Kind::Headers => packet::GET_BLOCK_HEADERS, request::Kind::Bodies => packet::GET_BLOCK_BODIES, diff --git a/sync/src/light_sync/mod.rs b/sync/src/light_sync/mod.rs index 5ca441949..821d0a4b2 100644 --- a/sync/src/light_sync/mod.rs +++ b/sync/src/light_sync/mod.rs @@ -193,9 +193,11 @@ impl Handler for LightSync { head_num: status.head_num, }; - let mut best = self.best_seen.lock(); - if best.as_ref().map_or(true, |b| status.head_td > b.1) { - *best = Some((status.head_hash, status.head_td)); + { + let mut best = self.best_seen.lock(); + if best.as_ref().map_or(true, |b| status.head_td > b.1) { + *best = Some((status.head_hash, status.head_td)); + } } self.peers.write().insert(ctx.peer(), Mutex::new(Peer::new(chain_info))); @@ -210,6 +212,8 @@ impl Handler for LightSync { None => return, }; + trace!(target: "sync", "peer {} disconnecting", peer_id); + let new_best = { let mut best = self.best_seen.lock(); let peer_best = (peer.status.head_hash, peer.status.head_td); @@ -249,7 +253,7 @@ impl Handler for LightSync { fn on_announcement(&self, ctx: &EventContext, announcement: &Announcement) { let last_td = { let peers = self.peers.read(); - match peers.get(&ctx.peer()){ + match peers.get(&ctx.peer()) { None => return, Some(peer) => { let mut peer = peer.lock(); @@ -273,9 +277,11 @@ impl Handler for LightSync { ctx.disconnect_peer(ctx.peer()); } - let mut best = self.best_seen.lock(); - if best.as_ref().map_or(true, |b| announcement.head_td > b.1) { - *best = Some((announcement.head_hash, announcement.head_td)); + { + let mut best = self.best_seen.lock(); + if best.as_ref().map_or(true, |b| announcement.head_td > b.1) { + *best = Some((announcement.head_hash, announcement.head_td)); + } } self.maintain_sync(ctx.as_basic()); @@ -326,12 +332,16 @@ impl LightSync { return; } + trace!(target: "sync", "Beginning search for common ancestor"); + *state = SyncState::AncestorSearch(AncestorSearch::begin(chain_info.best_block_number)); } fn maintain_sync(&self, ctx: &BasicContext) { const DRAIN_AMOUNT: usize = 128; + debug!(target: "sync", "Maintaining sync."); + let mut state = self.state.lock(); // drain any pending blocks into the queue.