Remove peer from active_peers when Peer_validator.create has failed
This commit is contained in:
parent
3e2172b2dd
commit
7e4a70fac8
@ -148,7 +148,11 @@ let with_activated_peer_validator w peer_id f =
|
||||
peer_id in
|
||||
P2p_peer.Table.add nv.active_peers peer_id pv ;
|
||||
pv
|
||||
end >>=? fun pv ->
|
||||
end >>= function
|
||||
| Error _ as e ->
|
||||
P2p_peer.Table.remove nv.active_peers peer_id ;
|
||||
Lwt.return e
|
||||
| Ok pv ->
|
||||
match Peer_validator.status pv with
|
||||
| Worker_types.Running _ -> f pv
|
||||
| Worker_types.Closing (_, _)
|
||||
@ -348,11 +352,13 @@ let on_close w =
|
||||
Distributed_db.deactivate nv.parameters.chain_db >>= fun () ->
|
||||
begin
|
||||
P2p_peer.Table.fold
|
||||
(fun _ pv acc ->
|
||||
(fun peer_id pv acc ->
|
||||
acc >>= fun acc ->
|
||||
pv >|= function
|
||||
| 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 [])
|
||||
end >>= fun pvs ->
|
||||
Lwt.join
|
||||
@ -408,9 +414,9 @@ let on_launch start_prevalidator w _ parameters =
|
||||
Distributed_db.set_callback parameters.chain_db {
|
||||
notify_branch = begin fun peer_id locator ->
|
||||
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 ;
|
||||
return_unit)
|
||||
return_unit
|
||||
end
|
||||
end ;
|
||||
notify_head = begin fun peer_id block ops ->
|
||||
@ -430,12 +436,15 @@ let on_launch start_prevalidator w _ parameters =
|
||||
Lwt.async begin fun () ->
|
||||
let nv = Worker.state w in
|
||||
match P2p_peer.Table.find_opt nv.active_peers peer_id with
|
||||
| None -> return_unit
|
||||
| Some pv ->
|
||||
pv >>=? fun pv ->
|
||||
pv >>= function
|
||||
| Error _ as e ->
|
||||
P2p_peer.Table.remove nv.active_peers peer_id ;
|
||||
Lwt.return e
|
||||
| Ok pv ->
|
||||
Peer_validator.shutdown pv >>= fun () ->
|
||||
return_unit
|
||||
| None ->
|
||||
return_unit
|
||||
end
|
||||
end ;
|
||||
} ;
|
||||
|
Loading…
Reference in New Issue
Block a user