P2p: postpone the first maintenance step.
This commit is contained in:
parent
5ee3581d60
commit
2da0c83b5a
@ -261,9 +261,8 @@ type ('msg, 'meta) t = {
|
||||
}
|
||||
type ('msg, 'meta) net = ('msg, 'meta) t
|
||||
|
||||
let bootstrap ~config ~limits meta_cfg msg_cfg =
|
||||
let create ~config ~limits meta_cfg msg_cfg =
|
||||
Real.create ~config ~limits meta_cfg msg_cfg >>= fun net ->
|
||||
Real.maintain net () >>= fun () ->
|
||||
Lwt.return {
|
||||
gid = Real.gid net ;
|
||||
maintain = Real.maintain net ;
|
||||
|
@ -124,7 +124,7 @@ type ('msg, 'meta) net = ('msg, 'meta) t
|
||||
val faked_network : ('msg, 'meta) net
|
||||
|
||||
(** Main network initialisation function *)
|
||||
val bootstrap :
|
||||
val create :
|
||||
config:config -> limits:limits ->
|
||||
'meta meta_config -> 'msg message_config -> ('msg, 'meta) net Lwt.t
|
||||
|
||||
|
@ -211,7 +211,10 @@ let init_p2p net_params =
|
||||
Lwt.return Tezos_p2p.faked_network
|
||||
| Some (config, limits) ->
|
||||
lwt_log_notice "bootstraping network..." >>= fun () ->
|
||||
Tezos_p2p.bootstrap config limits
|
||||
Tezos_p2p.create config limits >>= fun p2p ->
|
||||
Lwt.async (fun () -> Tezos_p2p.maintain p2p) ;
|
||||
Lwt.return p2p
|
||||
|
||||
|
||||
let create
|
||||
~genesis ~store_root ~context_root ?test_protocol ?patch_context net_params =
|
||||
@ -234,11 +237,12 @@ let create
|
||||
end >>=? fun global_net ->
|
||||
Validator.activate validator global_net >>= fun global_validator ->
|
||||
let cleanup () =
|
||||
Tezos_p2p.shutdown p2p >>= fun () ->
|
||||
Lwt.join [ Validator.shutdown validator ;
|
||||
Discoverer.shutdown discoverer ] >>= fun () ->
|
||||
State.store state
|
||||
in
|
||||
|
||||
let canceler = Lwt_utils.Canceler.create () in
|
||||
lwt_log_info "starting worker..." >>= fun () ->
|
||||
let worker =
|
||||
let handle_msg peer msg =
|
||||
@ -249,22 +253,23 @@ let create
|
||||
Lwt.return_unit
|
||||
in
|
||||
let rec worker_loop () =
|
||||
Tezos_p2p.recv p2p >>= fun (peer, msg) ->
|
||||
Lwt_utils.protect ~canceler begin fun () ->
|
||||
Tezos_p2p.recv p2p >>= return
|
||||
end >>=? fun (peer, msg) ->
|
||||
handle_msg peer msg >>= fun () ->
|
||||
worker_loop () in
|
||||
Lwt.catch
|
||||
worker_loop
|
||||
(function
|
||||
| Queue.Empty -> cleanup ()
|
||||
| exn ->
|
||||
lwt_log_error "unexpected exception in worker\n%s"
|
||||
(Printexc.to_string exn) >>= fun () ->
|
||||
Tezos_p2p.shutdown p2p >>= fun () ->
|
||||
cleanup ())
|
||||
worker_loop () >>= function
|
||||
| Error [Lwt_utils.Canceled] | Ok () ->
|
||||
cleanup ()
|
||||
| Error err ->
|
||||
lwt_log_error
|
||||
"@[Unexpected error in worker@ %a@]"
|
||||
pp_print_error err >>= fun () ->
|
||||
cleanup ()
|
||||
in
|
||||
let shutdown () =
|
||||
lwt_log_info "stopping worker..." >>= fun () ->
|
||||
Tezos_p2p.shutdown p2p >>= fun () ->
|
||||
Lwt_utils.Canceler.cancel canceler >>= fun () ->
|
||||
worker >>= fun () ->
|
||||
lwt_log_info "stopped"
|
||||
in
|
||||
|
@ -106,8 +106,8 @@ and msg_cfg : _ P2p.message_config = {
|
||||
|
||||
type net = (Message.t, Metadata.t) P2p.net
|
||||
|
||||
let bootstrap ~config ~limits =
|
||||
P2p.bootstrap ~config ~limits meta_cfg msg_cfg
|
||||
let create ~config ~limits =
|
||||
P2p.create ~config ~limits meta_cfg msg_cfg
|
||||
|
||||
let broadcast = P2p.broadcast
|
||||
let try_send = P2p.try_send
|
||||
|
@ -8,7 +8,7 @@ type net
|
||||
val faked_network : net
|
||||
|
||||
(** Main network initialisation function *)
|
||||
val bootstrap : config:config -> limits:limits -> net Lwt.t
|
||||
val create : config:config -> limits:limits -> net Lwt.t
|
||||
|
||||
(** A maintenance operation : try and reach the ideal number of peers *)
|
||||
val maintain : net -> unit Lwt.t
|
||||
|
Loading…
Reference in New Issue
Block a user