Distributed_db: don't fail when receiving a notification for a closing worker
This commit is contained in:
parent
a3379065ea
commit
3e2172b2dd
@ -125,29 +125,35 @@ 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
|
||||||
match P2p_peer.Table.find_opt nv.active_peers peer_id with
|
begin
|
||||||
| Some pv ->
|
match P2p_peer.Table.find_opt nv.active_peers peer_id with
|
||||||
pv
|
| Some pv -> pv
|
||||||
| None ->
|
| None ->
|
||||||
let pv =
|
let pv =
|
||||||
Peer_validator.create
|
Peer_validator.create
|
||||||
~notify_new_block:(notify_new_block w)
|
~notify_new_block:(notify_new_block w)
|
||||||
~notify_bootstrapped: begin fun () ->
|
~notify_bootstrapped: begin fun () ->
|
||||||
P2p_peer.Table.add nv.bootstrapped_peers peer_id () ;
|
P2p_peer.Table.add nv.bootstrapped_peers peer_id () ;
|
||||||
may_toggle_bootstrapped_chain w
|
may_toggle_bootstrapped_chain w
|
||||||
end
|
end
|
||||||
~notify_termination: begin fun _pv ->
|
~notify_termination: begin fun _pv ->
|
||||||
P2p_peer.Table.remove nv.active_peers peer_id ;
|
P2p_peer.Table.remove nv.active_peers peer_id ;
|
||||||
P2p_peer.Table.remove nv.bootstrapped_peers peer_id ;
|
P2p_peer.Table.remove nv.bootstrapped_peers peer_id ;
|
||||||
end
|
end
|
||||||
nv.parameters.peer_validator_limits
|
nv.parameters.peer_validator_limits
|
||||||
nv.parameters.block_validator
|
nv.parameters.block_validator
|
||||||
nv.parameters.chain_db
|
nv.parameters.chain_db
|
||||||
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 ->
|
||||||
|
Loading…
Reference in New Issue
Block a user