Correct recent beacon block request bug

This commit is contained in:
Age Manning 2019-09-05 22:18:17 +10:00
parent a3877b6135
commit ee25766cae
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
2 changed files with 22 additions and 10 deletions

View File

@ -187,7 +187,11 @@ pub(crate) enum ImportManagerOutcome {
request: BeaconBlocksRequest,
},
/// A `RecentBeaconBlocks` request is required.
RecentRequest(PeerId, RecentBeaconBlocksRequest),
RecentRequest {
peer_id: PeerId,
request_id: RequestId,
request: RecentBeaconBlocksRequest,
},
/// Updates information with peer via requesting another HELLO handshake.
Hello(PeerId),
/// A peer has caused a punishable error and should be downvoted.
@ -532,7 +536,7 @@ impl<T: BeaconChainTypes> ImportManager<T> {
pub fn add_unknown_block(&mut self, block: BeaconBlock<T::EthSpec>, peer_id: PeerId) {
// if we are not in regular sync mode, ignore this block
if let ManagerState::Regular = self.state {
if self.state != ManagerState::Regular {
return;
}
@ -774,19 +778,23 @@ impl<T: BeaconChainTypes> ImportManager<T> {
continue;
}
parent_request.state = BlockRequestsState::Pending(self.current_req_id);
let request_id = self.current_req_id;
parent_request.state = BlockRequestsState::Pending(request_id);
self.current_req_id += 1;
let last_element_index = parent_request.downloaded_blocks.len() - 1;
let parent_hash = parent_request.downloaded_blocks[last_element_index].parent_root;
let req = RecentBeaconBlocksRequest {
let request = RecentBeaconBlocksRequest {
block_roots: vec![parent_hash],
};
// select a random fully synced peer to attempt to download the parent block
let peer_id = self.full_peers.iter().next().expect("List is not empty");
self.event_queue
.push(ImportManagerOutcome::RecentRequest(peer_id.clone(), req));
self.event_queue.push(ImportManagerOutcome::RecentRequest {
peer_id: peer_id.clone(),
request_id,
request,
});
re_run = true;
}
}

View File

@ -277,18 +277,22 @@ impl<T: BeaconChainTypes> SimpleSync<T> {
RPCRequest::BeaconBlocks(request),
);
}
ImportManagerOutcome::RecentRequest(peer_id, req) => {
ImportManagerOutcome::RecentRequest {
peer_id,
request_id,
request,
} => {
trace!(
self.log,
"RPC Request";
"method" => "RecentBeaconBlocks",
"count" => req.block_roots.len(),
"count" => request.block_roots.len(),
"peer" => format!("{:?}", peer_id)
);
self.network.send_rpc_request(
None,
Some(request_id),
peer_id.clone(),
RPCRequest::RecentBeaconBlocks(req),
RPCRequest::RecentBeaconBlocks(request),
);
}
ImportManagerOutcome::DownvotePeer(peer_id) => {