Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinOndejka committed Dec 17, 2024
1 parent 09b357e commit 95d69f7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/app/zeko/da_layer/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ let sync_node =
~config:(Da_layer.Client.Config.of_node_locations [ synced_node ])
~source_ledger_hash:`Genesis
~target_ledger_hash:(Ledger_hash.of_decimal_string hash_to_sync)
~f:(fun progress diff ->
Zeko_util.progress_bar progress ;
~print_progress:true
~f:(fun diff ->
let diff = Da_layer.Diff.drop_time diff in
let ledger_openings = Da_layer.Client.get_openings ~diff ~ledger in
match%bind
Expand Down
10 changes: 7 additions & 3 deletions src/app/zeko/da_layer/lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,18 @@ let get_lazy_diffs_chunks ~logger ~depth ~config ?(n = 100) ~source_ledger_hash
~source_ledger_hash:(`Specific source)
~target_ledger_hash:target () ) ) )

let map_diffs ~logger ~depth ~config ~source_ledger_hash ~target_ledger_hash ~f
=
let map_diffs ~logger ~depth ~config ~source_ledger_hash ~target_ledger_hash
~print_progress ~f =
let%bind.Deferred.Result lazy_chunks =
get_lazy_diffs_chunks ~logger ~depth ~config ~source_ledger_hash
~target_ledger_hash ()
in
let l = List.length lazy_chunks in
Deferred.List.mapi ~how:`Sequential lazy_chunks ~f:(fun i lazy_chunk ->
let progress = Float.of_int i /. Float.of_int l in
if print_progress then Zeko_util.progress_bar progress ;
let%bind.Deferred.Result diffs = Lazy.force lazy_chunk in
Deferred.List.map ~how:`Sequential diffs ~f:(f progress) >>| Result.return )
Deferred.List.map ~how:`Sequential diffs ~f >>| Result.return )
>>| Result.all >>| Result.map ~f:List.join

(** Try to get the diff from the first node in the list, if it fails, try the next one *)
Expand Down Expand Up @@ -322,4 +323,7 @@ let check_synced_nodes ~logger ~(config : Config.t) ~target_ledger_hash =
| Ok (Some _) ->
return ( (* synced node *) )
| Ok None | Error _ ->
printf
!"Node %s is not synced\n%!"
(Host_and_port.to_string node.value) ;
return (Config.throw_out_node config ~node) )
4 changes: 2 additions & 2 deletions src/app/zeko/da_layer/lib/node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ let sync t ~node_location ~ledger_hash =
Client.map_diffs ~logger ~depth:constraint_constants.ledger_depth
~config:(Client.Config.of_node_locations [ node_location ])
~source_ledger_hash:`Genesis ~target_ledger_hash:ledger_hash
~f:(fun progress diff ->
Zeko_util.progress_bar progress ;
~print_progress:true
~f:(fun diff ->
let diff = Diff.drop_time diff in
let ledger_openings = Client.get_openings ~diff ~ledger in
match post_diff t ~diff ~ledger_openings with
Expand Down
5 changes: 2 additions & 3 deletions src/app/zeko/sequencer/archive_relay/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ let sync_archive ~(state : State.t) ~hash =
Da_layer.Client.map_diffs ~logger ~config:state.da_config
~depth:constraint_constants.ledger_depth
~source_ledger_hash:(`Specific (Ledger.Db.merkle_root state.ledger_cache))
~target_ledger_hash:hash
~f:(fun progress diff ->
Zeko_util.progress_bar progress ;
~target_ledger_hash:hash ~print_progress:true
~f:(fun diff ->
match Da_layer.Diff.Stable.Latest.command_with_action_step_flags diff with
| None ->
(* Apply accounts diff *)
Expand Down
5 changes: 3 additions & 2 deletions src/app/zeko/sequencer/lib/zeko_sequencer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ module Sequencer = struct
don't_wait_for @@ Deferred.ignore_m @@ commit t )

let bootstrap ~logger ({ config; _ } as t) da_config =
print_endline "Bootstrapping" ;
let%bind committed_ledger_hash =
Gql_client.infer_committed_state config.l1_uri ~zkapp_pk:config.zkapp_pk
~signer_pk:(Public_key.compress config.signer.public_key)
Expand All @@ -790,8 +791,8 @@ module Sequencer = struct
let%bind () =
Da_layer.Client.map_diffs ~logger ~config:da_config
~depth:constraint_constants.ledger_depth ~source_ledger_hash:`Genesis
~target_ledger_hash:committed_ledger_hash ~f:(fun progress diff ->
Zeko_util.progress_bar progress ;
~print_progress:true ~target_ledger_hash:committed_ledger_hash
~f:(fun diff ->
assert (
Ledger_hash.equal
(Da_layer.Diff.Stable.Latest.source_ledger_hash diff)
Expand Down
13 changes: 10 additions & 3 deletions src/app/zeko/zeko_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,14 @@ let progress_bar ?(width = 30) progress =
let bar =
String.make filled_length '#' ^ String.make (width - filled_length) '-'
in
let no_bar = Sys.getenv_opt "ZEKO_NO_PROGRESS_BAR" in
if Option.is_some no_bar then Printf.printf "%.0f%%%!" (progress *. 100.0)
else Printf.printf "\r[%s] %.0f%%%!" bar (progress *. 100.0) ;
let progress_style = Sys.getenv_opt "ZEKO_PROGRESS_STYLE" in
let () =
match progress_style with
| Some "percent" ->
Printf.printf "%.0f%%\n%!" (progress *. 100.0)
| Some "no" ->
()
| Some "bar" | Some _ | None ->
Printf.printf "\r[%s] %.0f%%%!" bar (progress *. 100.0)
in
if Float.(progress >= 1.0) then Printf.printf "\n%!"

0 comments on commit 95d69f7

Please sign in to comment.