Distributed_db: don't fail when receiving a notification for a closing worker
This commit is contained in:
parent
a3379065ea
commit
3e2172b2dd
@ -125,11 +125,11 @@ let may_toggle_bootstrapped_chain w =
|
||||
Lwt.wakeup_later nv.bootstrapped_wakener () ;
|
||||
end
|
||||
|
||||
let may_activate_peer_validator w peer_id =
|
||||
let with_activated_peer_validator w peer_id f =
|
||||
let nv = Worker.state w in
|
||||
begin
|
||||
match P2p_peer.Table.find_opt nv.active_peers peer_id with
|
||||
| Some pv ->
|
||||
pv
|
||||
| Some pv -> pv
|
||||
| None ->
|
||||
let pv =
|
||||
Peer_validator.create
|
||||
@ -148,6 +148,12 @@ let may_activate_peer_validator w peer_id =
|
||||
peer_id in
|
||||
P2p_peer.Table.add nv.active_peers peer_id 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 =
|
||||
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 {
|
||||
notify_branch = begin fun peer_id locator ->
|
||||
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 ;
|
||||
return_unit
|
||||
return_unit)
|
||||
end
|
||||
end ;
|
||||
notify_head = begin fun peer_id block ops ->
|
||||
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 ;
|
||||
return_unit) >>=? fun () ->
|
||||
(* TODO notify prevalidator only if head is known ??? *)
|
||||
match nv.prevalidator with
|
||||
| Some prevalidator ->
|
||||
|
Loading…
Reference in New Issue
Block a user