Client/Baker: let the baking daemon reveal nonces
This commit is contained in:
parent
f7a70f355c
commit
34e1764bce
@ -280,7 +280,44 @@ let compute_timeout { future_slots } =
|
|||||||
else
|
else
|
||||||
Lwt_unix.sleep (Int64.to_float delay)
|
Lwt_unix.sleep (Int64.to_float delay)
|
||||||
|
|
||||||
let insert_block cctxt ?max_priority state (bi: Client_mining_blocks.block_info) =
|
let get_unrevealed_nonces cctxt ?(force = false) block =
|
||||||
|
Client_proto_rpcs.Context.next_level cctxt block >>=? fun level ->
|
||||||
|
let cur_cycle = level.cycle in
|
||||||
|
match Cycle.pred cur_cycle with
|
||||||
|
| None -> return []
|
||||||
|
| Some cycle ->
|
||||||
|
Client_mining_blocks.blocks_from_cycle
|
||||||
|
cctxt block cycle >>=? fun block_infos ->
|
||||||
|
map_filter_s (fun (bi : Client_mining_blocks.block_info) ->
|
||||||
|
Client_proto_nonces.find cctxt bi.hash >>= function
|
||||||
|
| None -> return None
|
||||||
|
| Some nonce ->
|
||||||
|
if force then
|
||||||
|
return (Some (bi.hash, (bi.level.level, nonce)))
|
||||||
|
else
|
||||||
|
Client_proto_rpcs.Context.Nonce.get
|
||||||
|
cctxt block bi.level.level >>=? function
|
||||||
|
| Missing nonce_hash
|
||||||
|
when Nonce.check_hash nonce nonce_hash ->
|
||||||
|
cctxt.warning "Found nonce for %a (level: %a)@."
|
||||||
|
Block_hash.pp_short bi.hash
|
||||||
|
Level.pp bi.level >>= fun () ->
|
||||||
|
return (Some (bi.hash, (bi.level.level, nonce)))
|
||||||
|
| Missing _nonce_hash ->
|
||||||
|
cctxt.error "Incoherent nonce for level %a"
|
||||||
|
Raw_level.pp bi.level.level >>= fun () ->
|
||||||
|
return None
|
||||||
|
| Forgotten -> return None
|
||||||
|
| Revealed _ -> return None)
|
||||||
|
block_infos
|
||||||
|
|
||||||
|
let insert_block
|
||||||
|
cctxt ?max_priority state (bi: Client_mining_blocks.block_info) =
|
||||||
|
begin
|
||||||
|
get_unrevealed_nonces cctxt (`Hash bi.hash) >>=? fun nonces ->
|
||||||
|
Client_mining_revelation.forge_seed_nonce_revelation
|
||||||
|
cctxt ~force:true (`Hash bi.hash) (List.map snd nonces)
|
||||||
|
end >>= fun _ignore_error ->
|
||||||
if Fitness.compare state.best_fitness bi.fitness < 0 then
|
if Fitness.compare state.best_fitness bi.fitness < 0 then
|
||||||
state.best_fitness <- bi.fitness ;
|
state.best_fitness <- bi.fitness ;
|
||||||
get_mining_slot cctxt ?max_priority bi state.delegates >>= function
|
get_mining_slot cctxt ?max_priority bi state.delegates >>= function
|
||||||
|
@ -52,3 +52,9 @@ val create:
|
|||||||
Client_mining_blocks.block_info list Lwt_stream.t ->
|
Client_mining_blocks.block_info list Lwt_stream.t ->
|
||||||
Client_mining_operations.valid_endorsement Lwt_stream.t ->
|
Client_mining_operations.valid_endorsement Lwt_stream.t ->
|
||||||
unit Lwt.t
|
unit Lwt.t
|
||||||
|
|
||||||
|
val get_unrevealed_nonces:
|
||||||
|
Client_commands.context ->
|
||||||
|
?force:bool ->
|
||||||
|
Client_proto_rpcs.block ->
|
||||||
|
(Block_hash.t * (Raw_level.t * Nonce.t)) list tzresult Lwt.t
|
||||||
|
@ -86,19 +86,9 @@ let reveal_block_nonces cctxt ?force block_hashes =
|
|||||||
|
|
||||||
let reveal_nonces cctxt ?force () =
|
let reveal_nonces cctxt ?force () =
|
||||||
let block = Client_proto_args.block () in
|
let block = Client_proto_args.block () in
|
||||||
Client_proto_rpcs.Context.next_level cctxt block >>=? fun level ->
|
Client_mining_forge.get_unrevealed_nonces
|
||||||
let cur_cycle = level.cycle in
|
cctxt ?force block >>=? fun nonces ->
|
||||||
get_predecessor_cycle cctxt cur_cycle >>= fun cycle ->
|
do_reveal cctxt ?force block nonces
|
||||||
Client_mining_blocks.blocks_from_cycle cctxt block cycle >>=? fun block_infos ->
|
|
||||||
map_filter_s (fun (bi : Client_mining_blocks.block_info) ->
|
|
||||||
Client_proto_nonces.find cctxt bi.hash >>= function
|
|
||||||
| None -> return None
|
|
||||||
| Some nonce ->
|
|
||||||
cctxt.warning "Found nonce for %a (level: %a)@."
|
|
||||||
Block_hash.pp_short bi.hash Level.pp bi.level >>= fun () ->
|
|
||||||
return (Some (bi.hash, (bi.level.level, nonce))))
|
|
||||||
block_infos >>=? fun blocks ->
|
|
||||||
do_reveal cctxt ?force block blocks
|
|
||||||
|
|
||||||
open Client_proto_args
|
open Client_proto_args
|
||||||
|
|
||||||
|
@ -24,29 +24,9 @@ let inject_seed_nonce_revelation cctxt block ?force ?wait nonces =
|
|||||||
|
|
||||||
type Error_monad.error += Bad_revelation
|
type Error_monad.error += Bad_revelation
|
||||||
|
|
||||||
let forge_seed_nonce_revelation cctxt
|
let forge_seed_nonce_revelation
|
||||||
block ?(force = false) redempted_nonces =
|
(cctxt: Client_commands.context)
|
||||||
begin
|
block ?(force = false) nonces =
|
||||||
if force then return redempted_nonces else
|
|
||||||
map_filter_s (fun (level, nonce) ->
|
|
||||||
Client_proto_rpcs.Context.Nonce.get cctxt block level >>=? function
|
|
||||||
| Forgotten ->
|
|
||||||
cctxt.message "Too late revelation for level %a"
|
|
||||||
Raw_level.pp level >>= fun () ->
|
|
||||||
return None
|
|
||||||
| Revealed _ ->
|
|
||||||
cctxt.message "Ignoring previously-revealed nonce for level %a"
|
|
||||||
Raw_level.pp level >>= fun () ->
|
|
||||||
return None
|
|
||||||
| Missing nonce_hash ->
|
|
||||||
if Nonce.check_hash nonce nonce_hash then
|
|
||||||
return (Some (level, nonce))
|
|
||||||
else
|
|
||||||
lwt_log_error "Incoherent nonce for level %a"
|
|
||||||
Raw_level.pp level >>= fun () ->
|
|
||||||
return None)
|
|
||||||
redempted_nonces
|
|
||||||
end >>=? fun nonces ->
|
|
||||||
match nonces with
|
match nonces with
|
||||||
| [] ->
|
| [] ->
|
||||||
cctxt.message "No nonce to reveal" >>= fun () ->
|
cctxt.message "No nonce to reveal" >>= fun () ->
|
||||||
|
Loading…
Reference in New Issue
Block a user