Alpha/Endorser: use lazy init for contracts
This gives the Endorser the same semantic as the Baker: the delegate keys are retreived once if not explicitely given as arguments.
This commit is contained in:
parent
0431a13611
commit
3f0da7668d
@ -77,7 +77,7 @@ let forge_endorsement (cctxt : #Proto_alpha.full)
|
||||
(** Worker *)
|
||||
|
||||
type state = {
|
||||
delegates: public_key_hash list ;
|
||||
delegates: public_key_hash list tzlazy ;
|
||||
delay: int64 ;
|
||||
mutable pending: endorsements option ;
|
||||
}
|
||||
@ -92,14 +92,6 @@ and endorsements = {
|
||||
let create_state delegates delay =
|
||||
{ delegates ; delay ; pending = None }
|
||||
|
||||
let get_delegates cctxt state =
|
||||
match state.delegates with
|
||||
| [] ->
|
||||
Client_keys.get_keys cctxt >>=? fun keys ->
|
||||
return (List.map (fun (_, pkh, _, _) -> pkh) keys)
|
||||
| _ :: _ as delegates ->
|
||||
return delegates
|
||||
|
||||
let endorse_for_delegate cctxt block delegate =
|
||||
let { Client_baking_blocks.hash ; level } = block in
|
||||
let b = `Hash (hash, 0) in
|
||||
@ -151,7 +143,7 @@ let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:int64) state bi =
|
||||
Block_hash.pp_short bi.hash >>= fun () ->
|
||||
let time = Time.(add (now ()) state.delay) in
|
||||
let timeout = Lwt_unix.sleep (Int64.to_float state.delay) in
|
||||
get_delegates cctxt state >>=? fun delegates ->
|
||||
tzforce state.delegates >>=? fun delegates ->
|
||||
filter_map_p
|
||||
(fun delegate ->
|
||||
allowed_to_endorse cctxt bi delegate >>=? function
|
||||
@ -195,6 +187,15 @@ let create
|
||||
last_get_block := Some t ;
|
||||
t
|
||||
| Some t -> t in
|
||||
|
||||
let contracts = match contracts with
|
||||
| [] ->
|
||||
tzlazy (fun () ->
|
||||
Client_keys.get_keys cctxt >>=? fun keys ->
|
||||
return (List.map (fun (_, pkh, _, _) -> pkh) keys)
|
||||
)
|
||||
| _ :: _ ->
|
||||
tzlazy (fun () -> return contracts) in
|
||||
let state = create_state contracts (Int64.of_int delay) in
|
||||
|
||||
(* main loop *)
|
||||
|
Loading…
Reference in New Issue
Block a user