Distributed_db: don't fail when receiving a notification for a closing worker

This commit is contained in:
Grégoire Henry 2019-03-04 19:40:28 +01:00 committed by Pierre Boutillier
parent a3379065ea
commit 3e2172b2dd
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C

View File

@ -125,11 +125,11 @@ let may_toggle_bootstrapped_chain w =
Lwt.wakeup_later nv.bootstrapped_wakener () ; Lwt.wakeup_later nv.bootstrapped_wakener () ;
end end
let may_activate_peer_validator w peer_id = let with_activated_peer_validator w peer_id f =
let nv = Worker.state w in let nv = Worker.state w in
begin
match P2p_peer.Table.find_opt nv.active_peers peer_id with match P2p_peer.Table.find_opt nv.active_peers peer_id with
| Some pv -> | Some pv -> pv
pv
| None -> | None ->
let pv = let pv =
Peer_validator.create Peer_validator.create
@ -148,6 +148,12 @@ let may_activate_peer_validator w peer_id =
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 ->
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) ->
@ -402,15 +408,16 @@ 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 () ->
may_activate_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 ->
Lwt.async begin fun () -> Lwt.async begin fun () ->
may_activate_peer_validator w peer_id >>=? fun pv -> with_activated_peer_validator w peer_id (fun pv ->
Peer_validator.notify_head pv block ; Peer_validator.notify_head pv block ;
return_unit) >>=? fun () ->
(* TODO notify prevalidator only if head is known ??? *) (* TODO notify prevalidator only if head is known ??? *)
match nv.prevalidator with match nv.prevalidator with
| Some prevalidator -> | Some prevalidator ->