Shell: improve pp for block locator

This commit is contained in:
bruno 2018-02-19 18:25:57 +01:00 committed by Benjamin Canou
parent f5e3d99e24
commit f600fc57d4
3 changed files with 25 additions and 4 deletions

View File

@ -16,7 +16,26 @@ and raw = Block_header.t * Block_hash.t list
let raw x = x let raw x = x
let pp ppf loc = Block_header.pp ppf (fst loc) let pp ppf (hd, h_lst) =
let repeats = 10 in
let coef = 2 in
(* list of hashes *)
let rec pp_hash_list ppf (h_lst , acc , d , r) =
match h_lst with
| [] ->
Format.fprintf ppf ""
| hd :: tl ->
let new_d = if r > 1 then d else d * coef in
let new_r = if r > 1 then r - 1 else repeats in
Format.fprintf ppf "%a (%i)\n%a" Block_hash.pp hd acc pp_hash_list (tl , acc - d , new_d , new_r) in
Format.fprintf ppf "%a (head)\n%a"
Block_hash.pp (Block_header.hash hd)
pp_hash_list (h_lst , -1, 1, repeats - 1)
let pp_short ppf (hd, h_lst) =
Format.fprintf ppf "head: %a, %d predecessors"
Block_hash.pp (Block_header.hash hd)
(List.length h_lst)
let encoding = let encoding =
let open Data_encoding in let open Data_encoding in

View File

@ -17,6 +17,8 @@ val raw: t -> raw
val pp : Format.formatter -> t -> unit val pp : Format.formatter -> t -> unit
val pp_short : Format.formatter -> t -> unit
val encoding: t Data_encoding.t val encoding: t Data_encoding.t
val compute: predecessor: (Block_hash.t -> int -> Block_hash.t option Lwt.t) -> val compute: predecessor: (Block_hash.t -> int -> Block_hash.t option Lwt.t) ->

View File

@ -136,9 +136,9 @@ let () =
~description:"Block locator is invalid." ~description:"Block locator is invalid."
~pp: (fun ppf (id, locator) -> ~pp: (fun ppf (id, locator) ->
Format.fprintf ppf Format.fprintf ppf
"Invalid block locator %a on peer %a" "Invalid block locator on peer %a:\n%a"
Block_locator.pp locator P2p_peer.Id.pp id
P2p_peer.Id.pp id) Block_locator.pp locator)
Data_encoding.(obj2 Data_encoding.(obj2
(req "id" P2p_peer.Id.encoding) (req "id" P2p_peer.Id.encoding)
(req "locator" Block_locator.encoding)) (req "locator" Block_locator.encoding))