Remove peer from active_peers when Peer_validator.create has failed

This commit is contained in:
Pierre Boutillier 2019-03-06 10:35:47 +01:00
parent 3e2172b2dd
commit 7e4a70fac8
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C

View File

@ -148,12 +148,16 @@ let with_activated_peer_validator w peer_id f =
peer_id in peer_id in
P2p_peer.Table.add nv.active_peers peer_id pv ; P2p_peer.Table.add nv.active_peers peer_id pv ;
pv pv
end >>=? fun pv -> end >>= function
match Peer_validator.status pv with | Error _ as e ->
| Worker_types.Running _ -> f pv P2p_peer.Table.remove nv.active_peers peer_id ;
| Worker_types.Closing (_, _) Lwt.return e
| Worker_types.Closed (_, _, _) | Ok pv ->
| Worker_types.Launching _ -> return_unit match Peer_validator.status pv with
| Worker_types.Running _ -> f pv
| Worker_types.Closing (_, _)
| Worker_types.Closed (_, _, _)
| Worker_types.Launching _ -> return_unit
let may_update_checkpoint chain_state new_head = let may_update_checkpoint chain_state new_head =
State.Chain.checkpoint chain_state >>= fun (old_level, _old_block) -> State.Chain.checkpoint chain_state >>= fun (old_level, _old_block) ->
@ -348,11 +352,13 @@ let on_close w =
Distributed_db.deactivate nv.parameters.chain_db >>= fun () -> Distributed_db.deactivate nv.parameters.chain_db >>= fun () ->
begin begin
P2p_peer.Table.fold P2p_peer.Table.fold
(fun _ pv acc -> (fun peer_id pv acc ->
acc >>= fun acc -> acc >>= fun acc ->
pv >|= function pv >|= function
| Ok pv -> Peer_validator.shutdown pv :: acc | Ok pv -> Peer_validator.shutdown pv :: acc
| Error _ -> acc) | Error _ ->
P2p_peer.Table.remove nv.active_peers peer_id ;
acc)
nv.active_peers (Lwt.return []) nv.active_peers (Lwt.return [])
end >>= fun pvs -> end >>= fun pvs ->
Lwt.join Lwt.join
@ -408,9 +414,9 @@ let on_launch start_prevalidator w _ parameters =
Distributed_db.set_callback parameters.chain_db { Distributed_db.set_callback parameters.chain_db {
notify_branch = begin fun peer_id locator -> notify_branch = begin fun peer_id locator ->
Lwt.async begin fun () -> Lwt.async begin fun () ->
with_activated_peer_validator w peer_id (fun pv -> with_activated_peer_validator w peer_id @@ fun pv ->
Peer_validator.notify_branch pv locator ; Peer_validator.notify_branch pv locator ;
return_unit) return_unit
end end
end ; end ;
notify_head = begin fun peer_id block ops -> notify_head = begin fun peer_id block ops ->
@ -430,12 +436,15 @@ let on_launch start_prevalidator w _ parameters =
Lwt.async begin fun () -> Lwt.async begin fun () ->
let nv = Worker.state w in let nv = Worker.state w in
match P2p_peer.Table.find_opt nv.active_peers peer_id with match P2p_peer.Table.find_opt nv.active_peers peer_id with
| None -> return_unit
| Some pv -> | Some pv ->
pv >>=? fun pv -> pv >>= function
Peer_validator.shutdown pv >>= fun () -> | Error _ as e ->
return_unit P2p_peer.Table.remove nv.active_peers peer_id ;
| None -> Lwt.return e
return_unit | Ok pv ->
Peer_validator.shutdown pv >>= fun () ->
return_unit
end end
end ; end ;
} ; } ;