Alpha/Baker,Endorser: dynamically find keys
This commit is contained in:
parent
d4974aefa8
commit
d71b1648d9
@ -77,7 +77,7 @@ let forge_endorsement (cctxt : #Proto_alpha.full)
|
||||
(** Worker *)
|
||||
|
||||
type state = {
|
||||
delegates: public_key_hash list tzlazy ;
|
||||
delegates: public_key_hash list ;
|
||||
delay: int64 ;
|
||||
mutable pending: endorsements option ;
|
||||
}
|
||||
@ -92,6 +92,13 @@ 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 ->
|
||||
let delegates = List.map (fun (_,pkh,_,_) -> pkh) keys in
|
||||
return delegates
|
||||
| (_ :: _) 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
|
||||
@ -143,7 +150,7 @@ let prepare_endorsement ~(max_past:int64) () (cctxt : #Proto_alpha.full) state b
|
||||
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
|
||||
tzforce state.delegates >>=? fun delegates ->
|
||||
get_delegates cctxt state >>=? fun delegates ->
|
||||
filter_p (allowed_to_endorse cctxt bi) delegates >>=? fun delegates ->
|
||||
state.pending <- Some {
|
||||
time ;
|
||||
@ -169,20 +176,12 @@ let create
|
||||
(cctxt: #Proto_alpha.full)
|
||||
?(max_past=110L)
|
||||
~delay
|
||||
contracts
|
||||
delegates
|
||||
block_stream
|
||||
=
|
||||
|
||||
let state_maker _ _ =
|
||||
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
|
||||
let state = create_state delegates (Int64.of_int delay) in
|
||||
return state
|
||||
in
|
||||
|
||||
|
@ -26,8 +26,10 @@ type state = {
|
||||
genesis: Block_hash.t ;
|
||||
index : Context.index ;
|
||||
|
||||
(* see [get_delegates] below to find delegates when the list is empty *)
|
||||
delegates: public_key_hash list ;
|
||||
|
||||
(* lazy-initialisation with retry-on-error *)
|
||||
delegates: public_key_hash list tzlazy ;
|
||||
constants: Constants.t tzlazy ;
|
||||
|
||||
(* truly mutable *)
|
||||
@ -45,6 +47,13 @@ let create_state genesis index delegates constants best =
|
||||
future_slots = [] ;
|
||||
}
|
||||
|
||||
let get_delegates cctxt state = match state.delegates with
|
||||
| [] ->
|
||||
Client_keys.get_keys cctxt >>=? fun keys ->
|
||||
let delegates = List.map (fun (_,pkh,_,_) -> pkh) keys in
|
||||
return delegates
|
||||
| (_ :: _) as delegates -> return delegates
|
||||
|
||||
let generate_seed_nonce () =
|
||||
match Nonce.of_bytes @@
|
||||
Rand.generate Constants.nonce_length with
|
||||
@ -456,7 +465,7 @@ let insert_block
|
||||
drop_old_slots
|
||||
~before:(Time.add state.best.timestamp (-1800L)) state ;
|
||||
end ;
|
||||
tzforce state.delegates >>=? fun delegates ->
|
||||
get_delegates cctxt state >>=? fun delegates ->
|
||||
get_baking_slot cctxt ?max_priority bi delegates >>= function
|
||||
| [] ->
|
||||
lwt_debug
|
||||
@ -736,14 +745,6 @@ let create
|
||||
=
|
||||
|
||||
let state_maker genesis_hash bi =
|
||||
let delegates = match delegates with
|
||||
| [] ->
|
||||
tzlazy (fun () ->
|
||||
Client_keys.get_keys cctxt >>=? fun keys ->
|
||||
let delegates = List.map (fun (_,pkh,_,_) -> pkh) keys in
|
||||
return delegates
|
||||
)
|
||||
| _ :: _ -> tzlazy (fun () -> return delegates) in
|
||||
let constants =
|
||||
tzlazy (fun () -> Alpha_services.Constants.all cctxt (`Main, `Head 0)) in
|
||||
Client_baking_simulator.load_context ~context_path >>= fun index ->
|
||||
|
Loading…
Reference in New Issue
Block a user