Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into dp/feature/eip-152-add-blake2-precompile
Browse files Browse the repository at this point in the history
* master:
  EIP 1108: Reduce alt_bn128 precompile gas costs (#11008)
  Fix deadlock in `network-devp2p` (#11013)
  Implement EIP-1283 reenable transition, EIP-1706 and EIP-2200 (#10191)
  • Loading branch information
dvdplm committed Sep 2, 2019
2 parents 2975573 + a9cb572 commit 30aceb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 2 additions & 5 deletions ethcore/builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,7 @@ impl Implementation for Blake2F {

let mut rdr = Cursor::new(input);
let rounds = rdr.read_u32::<BigEndian>().expect("todo – prove this is ok or handle");
// todo[dvdplm] is this even not an error? According to the EIP it is not. Seems fishy though.
// if rounds == 0 {
// return Err("No rounds argument passed");
// }

// state vector, h
let mut h = [0u64; 8];
for i in 0..8 {
Expand Down Expand Up @@ -667,7 +664,7 @@ mod tests {
use num::{BigUint, Zero, One};
use parity_bytes::BytesRef;
use rustc_hex::FromHex;
use hex_literal::hex;
use hex_literal::hex; // todo[dvdplm] switch tests to hex_literal
use super::{Builtin, Linear, ethereum_builtin, Pricer, ModexpPricer, modexp as me};

#[test]
Expand Down
16 changes: 11 additions & 5 deletions util/network-devp2p/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ struct ProtocolTimer {
}

/// Root IO handler. Manages protocol handlers, IO timers and network connections.
///
/// NOTE: must keep the lock in order of: reserved_nodes (rwlock) -> session (mutex, from sessions)
pub struct Host {
pub info: RwLock<HostInfo>,
udp_socket: Mutex<Option<UdpSocket>>,
Expand Down Expand Up @@ -722,12 +724,13 @@ impl Host {
let session_result = session.lock().readable(io, &self.info.read());
match session_result {
Err(e) => {
let reserved_nodes = self.reserved_nodes.read();
let s = session.lock();
trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e);
match e {
Error::Disconnect(DisconnectReason::IncompatibleProtocol) | Error::Disconnect(DisconnectReason::UselessPeer) => {
if let Some(id) = s.id() {
if !self.reserved_nodes.read().contains(id) {
if !reserved_nodes.contains(id) {
let mut nodes = self.nodes.write();
nodes.note_failure(&id);
nodes.mark_as_useless(id);
Expand All @@ -741,6 +744,7 @@ impl Host {
},
Ok(SessionData::Ready) => {
let (_, egress_count, ingress_count) = self.session_count();
let reserved_nodes = self.reserved_nodes.read();
let mut s = session.lock();
let (min_peers, mut max_peers, reserved_only, self_id) = {
let info = self.info.read();
Expand All @@ -765,7 +769,7 @@ impl Host {
if reserved_only ||
(s.info.originated && egress_count > min_peers) ||
(!s.info.originated && ingress_count > max_ingress) {
if !self.reserved_nodes.read().contains(&id) {
if !reserved_nodes.contains(&id) {
// only proceed if the connecting peer is reserved.
trace!(target: "network", "Disconnecting non-reserved peer {:?}", id);
s.disconnect(io, DisconnectReason::TooManyPeers);
Expand Down Expand Up @@ -980,7 +984,8 @@ impl Host {
for i in to_remove {
trace!(target: "network", "Removed from node table: {}", i);
}
self.nodes.write().update(node_changes, &*self.reserved_nodes.read());
let reserved_nodes = self.reserved_nodes.read();
self.nodes.write().update(node_changes, &*reserved_nodes);
}

pub fn with_context<F>(&self, protocol: ProtocolId, io: &IoContext<NetworkIoMessage>, action: F) where F: FnOnce(&dyn NetworkContextTrait) {
Expand Down Expand Up @@ -1066,8 +1071,9 @@ impl IoHandler<NetworkIoMessage> for Host {
},
NODE_TABLE => {
trace!(target: "network", "Refreshing node table");
self.nodes.write().clear_useless();
self.nodes.write().save();
let mut nodes = self.nodes.write();
nodes.clear_useless();
nodes.save();
},
_ => match self.timers.read().get(&token).cloned() {
Some(timer) => match self.handlers.read().get(&timer.protocol).cloned() {
Expand Down

0 comments on commit 30aceb5

Please sign in to comment.