fix deadlock in on_demand

This commit is contained in:
Robert Habermeier 2017-03-23 02:55:25 +01:00
parent 23a6b19985
commit a55001ad1d

View File

@ -210,7 +210,7 @@ impl OnDemand {
/// it as easily. /// it as easily.
pub fn header_by_hash(&self, ctx: &BasicContext, req: request::HeaderByHash) -> Receiver<encoded::Header> { pub fn header_by_hash(&self, ctx: &BasicContext, req: request::HeaderByHash) -> Receiver<encoded::Header> {
let (sender, receiver) = oneshot::channel(); let (sender, receiver) = oneshot::channel();
match self.cache.lock().block_header(&req.0) { match { self.cache.lock().block_header(&req.0) } {
Some(hdr) => sender.send(hdr).expect(RECEIVER_IN_SCOPE), Some(hdr) => sender.send(hdr).expect(RECEIVER_IN_SCOPE),
None => self.dispatch(ctx, Pending::HeaderByHash(req, sender)), None => self.dispatch(ctx, Pending::HeaderByHash(req, sender)),
} }
@ -232,7 +232,7 @@ impl OnDemand {
sender.send(encoded::Block::new(stream.out())).expect(RECEIVER_IN_SCOPE); sender.send(encoded::Block::new(stream.out())).expect(RECEIVER_IN_SCOPE);
} else { } else {
match self.cache.lock().block_body(&req.hash) { match { self.cache.lock().block_body(&req.hash) } {
Some(body) => { Some(body) => {
let mut stream = RlpStream::new_list(3); let mut stream = RlpStream::new_list(3);
stream.append_raw(&req.header.into_inner(), 1); stream.append_raw(&req.header.into_inner(), 1);
@ -255,7 +255,7 @@ impl OnDemand {
if req.0.receipts_root() == SHA3_NULL_RLP { if req.0.receipts_root() == SHA3_NULL_RLP {
sender.send(Vec::new()).expect(RECEIVER_IN_SCOPE); sender.send(Vec::new()).expect(RECEIVER_IN_SCOPE);
} else { } else {
match self.cache.lock().block_receipts(&req.0.hash()) { match { self.cache.lock().block_receipts(&req.0.hash()) } {
Some(receipts) => sender.send(receipts).expect(RECEIVER_IN_SCOPE), Some(receipts) => sender.send(receipts).expect(RECEIVER_IN_SCOPE),
None => self.dispatch(ctx, Pending::BlockReceipts(req, sender)), None => self.dispatch(ctx, Pending::BlockReceipts(req, sender)),
} }
@ -397,10 +397,12 @@ impl Handler for OnDemand {
} }
fn on_announcement(&self, ctx: &EventContext, announcement: &Announcement) { fn on_announcement(&self, ctx: &EventContext, announcement: &Announcement) {
let mut peers = self.peers.write(); {
if let Some(ref mut peer) = peers.get_mut(&ctx.peer()) { let mut peers = self.peers.write();
peer.status.update_from(&announcement); if let Some(ref mut peer) = peers.get_mut(&ctx.peer()) {
peer.capabilities.update_from(&announcement); peer.status.update_from(&announcement);
peer.capabilities.update_from(&announcement);
}
} }
self.dispatch_orphaned(ctx.as_basic()); self.dispatch_orphaned(ctx.as_basic());