Testnet corrections (#1050)

* Correct RPC ping request

* Add attestation verification

* Add discv5 bug fixes

* Reduce gossipsub heartbeat and update metadata

* Handle known chain of advanced peer
This commit is contained in:
Age Manning
2020-04-27 14:18:30 +10:00
committed by GitHub
parent fa8154e3da
commit 500f6b53d1
7 changed files with 176 additions and 141 deletions

View File

@@ -8,7 +8,7 @@ edition = "2018"
hex = "0.3"
# rust-libp2p is presently being sourced from a Sigma Prime fork of the
# `libp2p/rust-libp2p` repository.
libp2p = { git = "https://github.com/SigP/rust-libp2p", rev = "37b7e9349cf3e724da02bbd4b5dd6c054c2d56d3" }
libp2p = { git = "https://github.com/SigP/rust-libp2p", rev = "71cf486b4d992862f5a05f9f4ef5e5c1631f4add" }
types = { path = "../../eth2/types" }
hashmap_delay = { path = "../../eth2/utils/hashmap_delay" }
eth2_ssz_types = { path = "../../eth2/utils/ssz_types" }

View File

@@ -298,14 +298,17 @@ impl<TSubstream: AsyncRead + AsyncWrite, TSpec: EthSpec> Behaviour<TSubstream, T
}
/// Sends a PING/PONG request/response to a peer.
fn send_ping(&mut self, id: RequestId, peer_id: PeerId) {
let pong_response = RPCEvent::Response(
id,
RPCErrorResponse::Success(RPCResponse::Pong(crate::rpc::methods::Ping {
data: self.meta_data.seq_number,
})),
);
self.send_rpc(peer_id, pong_response);
fn send_ping(&mut self, id: RequestId, peer_id: PeerId, is_request: bool) {
let ping = crate::rpc::methods::Ping {
data: self.meta_data.seq_number,
};
let event = if is_request {
RPCEvent::Request(id, RPCRequest::Ping(ping))
} else {
RPCEvent::Response(id, RPCErrorResponse::Success(RPCResponse::Pong(ping)))
};
self.send_rpc(peer_id, event);
}
/// Sends a METADATA request to a peer.
@@ -425,7 +428,8 @@ impl<TSubstream: AsyncRead + AsyncWrite, TSpec: EthSpec>
RPCEvent::Request(id, RPCRequest::Ping(ping)) => {
// inform the peer manager and send the response
self.peer_manager.ping_request(&peer_id, ping.data);
self.send_ping(id, peer_id);
// send a ping response
self.send_ping(id, peer_id, false);
}
RPCEvent::Request(id, RPCRequest::MetaData(_)) => {
// send the requested meta-data
@@ -474,8 +478,8 @@ impl<TSubstream: AsyncRead + AsyncWrite, TSpec: EthSpec> Behaviour<TSubstream, T
));
}
PeerManagerEvent::Ping(peer_id) => {
// send a ping to this peer
self.send_ping(RequestId::from(0usize), peer_id);
// send a ping request to this peer
self.send_ping(RequestId::from(0usize), peer_id, true);
}
PeerManagerEvent::MetaData(peer_id) => {
self.send_meta_data_request(peer_id);

View File

@@ -101,7 +101,7 @@ impl Default for Config {
// parameter.
let gs_config = GossipsubConfigBuilder::new()
.max_transmit_size(GOSSIP_MAX_SIZE)
.heartbeat_interval(Duration::from_secs(20)) // TODO: Reduce for mainnet
.heartbeat_interval(Duration::from_secs(1))
.manual_propagation() // require validation before propagation
.no_source_id()
.message_id_fn(gossip_message_id)

View File

@@ -96,6 +96,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if let Some(peer_info) = self.network_globals.peers.read().peer_info(peer_id) {
// received a ping
// reset the to-ping timer for this peer
debug!(self.log, "Received a ping request"; "peer_id" => format!("{}", peer_id), "seq_no" => seq);
self.ping_peers.insert(peer_id.clone());
// if the sequence number is unknown send update the meta data of the peer.
@@ -147,6 +148,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if let Some(known_meta_data) = &peer_info.meta_data {
if known_meta_data.seq_number < meta_data.seq_number {
debug!(self.log, "Updating peer's metadata"; "peer_id" => format!("{}", peer_id), "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number);
peer_info.meta_data = Some(meta_data);
} else {
warn!(self.log, "Received old metadata"; "peer_id" => format!("{}", peer_id), "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number);
}
@@ -320,6 +322,8 @@ impl<TSpec: EthSpec> Stream for PeerManager<TSpec> {
error!(self.log, "Failed to check for peers to ping"; "error" => format!("{}",e));
})? {
debug!(self.log, "Pinging peer"; "peer_id" => format!("{}", peer_id));
// add the ping timer back
self.ping_peers.insert(peer_id.clone());
self.events.push(PeerManagerEvent::Ping(peer_id));
}
@@ -327,6 +331,8 @@ impl<TSpec: EthSpec> Stream for PeerManager<TSpec> {
error!(self.log, "Failed to check for peers to status"; "error" => format!("{}",e));
})? {
debug!(self.log, "Sending Status to peer"; "peer_id" => format!("{}", peer_id));
// add the status timer back
self.status_peers.insert(peer_id.clone());
self.events.push(PeerManagerEvent::Status(peer_id));
}