From e02b166b842973b886168959a904852bf306cde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Wed, 7 Nov 2018 16:30:18 +0100 Subject: [PATCH] Baker/Nonces: fix `reveal nonces` --- src/proto_alpha/lib_delegate/client_baking_forge.ml | 7 ++----- src/proto_alpha/lib_delegate/client_baking_forge.mli | 6 ++++++ src/proto_alpha/lib_delegate/client_baking_lib.ml | 9 +++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_forge.ml b/src/proto_alpha/lib_delegate/client_baking_forge.ml index fd2371880..d1d1c2590 100644 --- a/src/proto_alpha/lib_delegate/client_baking_forge.ml +++ b/src/proto_alpha/lib_delegate/client_baking_forge.ml @@ -944,9 +944,7 @@ let filter_outdated_nonces cctxt ~chain ~block:head () >>=? fun { protocol_data = { level = current_level } } -> let current_cycle = Cycle.to_int32 current_level.Level.cycle in let is_older_than_5_cycles block_cycle = - let delta = Int32.sub current_cycle block_cycle in - delta > 5l - in + Int32.sub current_cycle (Cycle.to_int32 block_cycle) > 5l in cctxt#with_lock begin fun () -> Client_baking_nonces.load cctxt >>=? fun nonces -> Block_hash.Map.fold @@ -954,8 +952,7 @@ let filter_outdated_nonces acc >>=? fun acc -> Alpha_block_services.metadata cctxt ~chain ~block:(`Hash (hash, 0)) () >>=? fun { protocol_data = { level = { Level.cycle } } } -> - let i = Cycle.to_int32 cycle in - if is_older_than_5_cycles i then + if is_older_than_5_cycles cycle then return acc else return (Block_hash.Map.add hash nonce acc) diff --git a/src/proto_alpha/lib_delegate/client_baking_forge.mli b/src/proto_alpha/lib_delegate/client_baking_forge.mli index e22eec347..3d49d496d 100644 --- a/src/proto_alpha/lib_delegate/client_baking_forge.mli +++ b/src/proto_alpha/lib_delegate/client_baking_forge.mli @@ -117,3 +117,9 @@ val get_unrevealed_nonces: ?chain:Chain_services.chain -> Block_services.block -> (Block_hash.t * (Raw_level.t * Nonce.t)) list tzresult Lwt.t + +val filter_outdated_nonces: + #Proto_alpha.full -> + ?chain:Block_services.chain -> + Shell_services.block -> + unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_delegate/client_baking_lib.ml b/src/proto_alpha/lib_delegate/client_baking_lib.ml index 6317908d6..66ebecc06 100644 --- a/src/proto_alpha/lib_delegate/client_baking_lib.ml +++ b/src/proto_alpha/lib_delegate/client_baking_lib.ml @@ -104,9 +104,8 @@ let get_predecessor_cycle (cctxt : #Client_context.printer) cycle = let do_reveal cctxt block blocks = let nonces = List.map snd blocks in - Client_baking_revelation.forge_seed_nonce_revelation cctxt - block nonces >>=? fun () -> - Client_baking_nonces.dels cctxt (List.map fst blocks) >>=? fun () -> + Client_baking_revelation.forge_seed_nonce_revelation + cctxt block nonces >>=? fun () -> return_unit let reveal_block_nonces (cctxt : #Proto_alpha.full) block_hashes = @@ -141,4 +140,6 @@ let reveal_block_nonces (cctxt : #Proto_alpha.full) block_hashes = let reveal_nonces cctxt () = Client_baking_forge.get_unrevealed_nonces cctxt cctxt#block >>=? fun nonces -> - do_reveal cctxt cctxt#block nonces + do_reveal cctxt cctxt#block nonces >>=? fun () -> + Client_baking_forge.filter_outdated_nonces cctxt cctxt#block >>=? fun () -> + return_unit