Baker/Nonces: improve nonces file reading
This commit is contained in:
parent
527a2fb621
commit
eda9d8c37f
@ -932,13 +932,21 @@ let compute_best_slot_on_current_level
|
|||||||
(* Found at least a slot *)
|
(* Found at least a slot *)
|
||||||
return_some best_slot
|
return_some best_slot
|
||||||
|
|
||||||
|
module Nonces_map = Map.Make(Block_hash)
|
||||||
|
|
||||||
(** [get_unrevealed_nonces] retrieve registered nonces *)
|
(** [get_unrevealed_nonces] retrieve registered nonces *)
|
||||||
let get_unrevealed_nonces
|
let get_unrevealed_nonces
|
||||||
(cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block =
|
(cctxt : #Proto_alpha.full) ?(force = false) ?(chain = `Main) block =
|
||||||
|
cctxt#with_lock begin fun () ->
|
||||||
|
Client_baking_nonces.load cctxt
|
||||||
|
end >>=? fun nonces ->
|
||||||
|
let nonces = List.fold_left
|
||||||
|
(fun map (hash, nonce) -> Nonces_map.add hash nonce map)
|
||||||
|
Nonces_map.empty nonces in
|
||||||
Client_baking_blocks.blocks_from_current_cycle
|
Client_baking_blocks.blocks_from_current_cycle
|
||||||
cctxt block ~offset:(-1l) () >>=? fun blocks ->
|
cctxt block ~offset:(-1l) () >>=? fun blocks ->
|
||||||
filter_map_s (fun hash ->
|
filter_map_s (fun hash ->
|
||||||
Client_baking_nonces.find cctxt hash >>=? function
|
match Nonces_map.find_opt hash nonces with
|
||||||
| None -> return_none
|
| None -> return_none
|
||||||
| Some nonce ->
|
| Some nonce ->
|
||||||
Alpha_block_services.metadata
|
Alpha_block_services.metadata
|
||||||
@ -950,14 +958,19 @@ let get_unrevealed_nonces
|
|||||||
cctxt (chain, block) level.level >>=? function
|
cctxt (chain, block) level.level >>=? function
|
||||||
| Missing nonce_hash
|
| Missing nonce_hash
|
||||||
when Nonce.check_hash nonce nonce_hash ->
|
when Nonce.check_hash nonce nonce_hash ->
|
||||||
cctxt#warning "Found nonce for %a (level: %a)@."
|
lwt_log_notice Tag.DSL.(fun f ->
|
||||||
Block_hash.pp_short hash
|
f "Found nonce to reveal for %a (level: %a)"
|
||||||
Level.pp level >>= fun () ->
|
-% t event "found_nonce"
|
||||||
|
-% a Block_hash.Logging.tag hash
|
||||||
|
-% a level_tag level.level)
|
||||||
|
>>= fun () ->
|
||||||
return_some (hash, (level.level, nonce))
|
return_some (hash, (level.level, nonce))
|
||||||
| Missing _nonce_hash ->
|
| Missing _nonce_hash ->
|
||||||
cctxt#error "Incoherent nonce for level %a"
|
lwt_log_error Tag.DSL.(fun f ->
|
||||||
Raw_level.pp level.level >>= fun () ->
|
f "Incoherent nonce for level %a"
|
||||||
return_none
|
-% t event "bad_nonce"
|
||||||
|
-% a level_tag level.level)
|
||||||
|
>>= fun () -> return_none
|
||||||
| Forgotten -> return_none
|
| Forgotten -> return_none
|
||||||
| Revealed _ -> return_none)
|
| Revealed _ -> return_none)
|
||||||
blocks
|
blocks
|
||||||
@ -970,7 +983,7 @@ let reveal_potential_nonces cctxt block =
|
|||||||
cctxt block (List.map snd nonces)
|
cctxt block (List.map snd nonces)
|
||||||
| Error err ->
|
| Error err ->
|
||||||
lwt_warn Tag.DSL.(fun f ->
|
lwt_warn Tag.DSL.(fun f ->
|
||||||
f "Cannot read nonces: %a@."
|
f "Cannot read nonces: %a"
|
||||||
-% t event "read_nonce_fail"
|
-% t event "read_nonce_fail"
|
||||||
-% a errs_tag err)
|
-% a errs_tag err)
|
||||||
>>= fun () ->
|
>>= fun () ->
|
||||||
|
@ -26,6 +26,11 @@
|
|||||||
open Proto_alpha
|
open Proto_alpha
|
||||||
open Alpha_context
|
open Alpha_context
|
||||||
|
|
||||||
|
type t = (Block_hash.t * Nonce.t) list
|
||||||
|
|
||||||
|
val load:
|
||||||
|
#Client_context.wallet ->
|
||||||
|
t tzresult Lwt.t
|
||||||
val mem:
|
val mem:
|
||||||
#Client_context.wallet ->
|
#Client_context.wallet ->
|
||||||
Block_hash.t -> bool tzresult Lwt.t
|
Block_hash.t -> bool tzresult Lwt.t
|
||||||
|
Loading…
Reference in New Issue
Block a user