Client: wait for the node to be bootstrapped before injecting an operation

This commit is contained in:
Pietro 2018-06-15 13:16:09 +02:00 committed by Benjamin Canou
parent 4c4400a073
commit 79b2a4e825
3 changed files with 28 additions and 1 deletions

View File

@ -7,6 +7,30 @@
(* *)
(**************************************************************************)
let wait_for_bootstrapped (ctxt : #Client_context.full) =
let display = ref false in
Lwt.async begin fun () ->
Lwt_unix.sleep 0.3 >>= fun () ->
if not !display then
ctxt#answer "Waiting for the node to be bootstrapped before injection..." >>= fun () ->
display := true ;
Lwt.return ()
else
Lwt.return ()
end ;
Monitor_services.bootstrapped ctxt >>=? fun (stream, _stop) ->
Lwt_stream.iter_s
(fun (hash, time) ->
if !display then
ctxt#message "Current head: %a (timestamp: %a, validation: %a)"
Block_hash.pp_short hash
Time.pp_hum time
Time.pp_hum (Time.now ())
else Lwt.return ()) stream >>= fun () ->
display := true ;
ctxt#answer "Node is bootstrapped, ready for injecting operations." >>= fun () ->
return ()
let wait_for_operation_inclusion
(ctxt : #Client_context.full)
~chain
@ -133,4 +157,3 @@ let wait_for_operation_inclusion
ctxt ~block:(`Hash (head, predecessors+1)) () >>=? fun oldest ->
Block_hash.Table.add blocks oldest None ;
loop predecessors

View File

@ -21,3 +21,6 @@ val wait_for_operation_inclusion:
?confirmations:int ->
Operation_hash.t ->
(Block_hash.t * int * int) tzresult Lwt.t
val wait_for_bootstrapped:
#Client_context.full -> unit tzresult Lwt.t

View File

@ -315,6 +315,7 @@ let may_patch_limits
let inject_operation
(type kind) cctxt ~chain ~block
?confirmations ?branch ?src_sk (contents: kind contents_list) =
Client_confirmations.wait_for_bootstrapped cctxt >>=? fun () ->
may_patch_limits
cctxt ~chain ~block ?branch contents >>=? fun contents ->
preapply cctxt ~chain ~block