Baker: do not generate empty endorsements

This commit is contained in:
Benjamin Canou 2018-06-18 18:56:52 +02:00 committed by Grégoire Henry
parent 7500743a4d
commit 41707f58d8
2 changed files with 40 additions and 33 deletions

View File

@ -19,8 +19,8 @@ let get_signing_slots cctxt ?(chain = `Main) block delegate level =
~levels:[level] ~levels:[level]
~delegates:[delegate] ~delegates:[delegate]
(chain, block) >>=? function (chain, block) >>=? function
| [{ slots }] -> return slots | [{ slots }] -> return (Some slots)
| _ -> (* TODO? log this case *) return [] | _ -> return None
let inject_endorsement let inject_endorsement
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
@ -73,8 +73,8 @@ let forge_endorsement (cctxt : #Proto_alpha.full)
| None -> | None ->
get_signing_slots get_signing_slots
cctxt ~chain block src_pkh level >>=? function cctxt ~chain block src_pkh level >>=? function
| [] -> cctxt#error "No slot found at level %a" Raw_level.pp level | None -> cctxt#error "No slot found at level %a" Raw_level.pp level
| slots -> return slots | Some slots -> return slots
end >>=? fun slots -> end >>=? fun slots ->
Shell_services.Blocks.hash cctxt ~chain ~block () >>=? fun hash -> Shell_services.Blocks.hash cctxt ~chain ~block () >>=? fun hash ->
inject_endorsement cctxt ~chain ?async block hash level src_sk slots src_pkh >>=? fun oph -> inject_endorsement cctxt ~chain ?async block hash level src_sk slots src_pkh >>=? fun oph ->
@ -167,6 +167,12 @@ let allowed_to_endorse cctxt state (block: Client_baking_blocks.block_info) dele
let b = `Hash (block.hash, 0) in let b = `Hash (block.hash, 0) in
let level = block.level in let level = block.level in
get_signing_slots cctxt b delegate level >>=? fun slots -> get_signing_slots cctxt b delegate level >>=? fun slots ->
match slots with
| None ->
lwt_debug "No slot found for %a/%s"
Block_hash.pp_short block.hash name >>= fun () ->
return ()
| Some slots ->
lwt_debug "Found slots for %a/%s (%d)" lwt_debug "Found slots for %a/%s (%d)"
Block_hash.pp_short block.hash name (List.length slots) >>= fun () -> Block_hash.pp_short block.hash name (List.length slots) >>= fun () ->
previously_endorsed_level cctxt delegate level >>=? function previously_endorsed_level cctxt delegate level >>=? function

View File

@ -514,7 +514,8 @@ let pop_baking_slots state =
let filter_invalid_operations (cctxt : #full) state block_info (operations : packed_operation list list) = let filter_invalid_operations (cctxt : #full) state block_info (operations : packed_operation list list) =
let open Client_baking_simulator in let open Client_baking_simulator in
lwt_debug "Starting client-side validation" >>= fun () -> lwt_debug "Starting client-side validation %a"
Block_hash.pp block_info.Client_baking_blocks.hash >>= fun () ->
begin_construction cctxt state.index block_info >>=? fun initial_inc -> begin_construction cctxt state.index block_info >>=? fun initial_inc ->
let endorsements = List.nth operations 0 in let endorsements = List.nth operations 0 in
let votes = List.nth operations 1 in let votes = List.nth operations 1 in
@ -656,9 +657,8 @@ let fit_enough (state: state) (shell_header: Block_header.shell_header) =
|| (Fitness.compare state.best.fitness shell_header.fitness = 0 || (Fitness.compare state.best.fitness shell_header.fitness = 0
&& Time.compare shell_header.timestamp state.best.timestamp < 0) && Time.compare shell_header.timestamp state.best.timestamp < 0)
let record_nonce_hash cctxt level block_hash seed_nonce seed_nonce_hash pkh = let record_nonce_hash cctxt block_hash seed_nonce seed_nonce_hash =
if seed_nonce_hash <> None then if seed_nonce_hash <> None then
State.record cctxt pkh level >>=? fun () ->
Client_baking_nonces.add cctxt block_hash seed_nonce Client_baking_nonces.add cctxt block_hash seed_nonce
|> trace_exn (Failure "Error while recording block") |> trace_exn (Failure "Error while recording block")
else else
@ -712,7 +712,8 @@ let bake (cctxt : #Proto_alpha.full) state =
(* /core function; back to logging and info *) (* /core function; back to logging and info *)
|> trace_exn (Failure "Error while injecting block") >>=? fun block_hash -> |> trace_exn (Failure "Error while injecting block") >>=? fun block_hash ->
record_nonce_hash cctxt level block_hash seed_nonce seed_nonce_hash src_pkh >>=? fun () -> State.record cctxt src_pkh level >>=? fun () ->
record_nonce_hash cctxt block_hash seed_nonce seed_nonce_hash >>=? fun () ->
Client_keys.Public_key_hash.name cctxt delegate >>=? fun name -> Client_keys.Public_key_hash.name cctxt delegate >>=? fun name ->
cctxt#message cctxt#message
"Injected block %a for %s after %a (level %a, slot %d, fitness %a, operations %a)" "Injected block %a for %s after %a (level %a, slot %d, fitness %a, operations %a)"