From 4b282ea8c53d34cb13647e0817dc5407b582bf2c Mon Sep 17 00:00:00 2001 From: Marco Stronati Date: Wed, 27 Jun 2018 16:57:05 +0200 Subject: [PATCH] Alpha: move block_metadata from alpha_context to apply_result --- .../client_baking_denunciation.ml | 2 +- .../lib_protocol/src/alpha_context.mli | 7 ------- .../lib_protocol/src/apply_results.ml | 19 +++++++++++++++++++ .../lib_protocol/src/apply_results.mli | 7 +++++++ .../lib_protocol/src/block_header_repr.ml | 18 ------------------ .../lib_protocol/src/block_header_repr.mli | 7 ------- src/proto_alpha/lib_protocol/src/main.ml | 14 ++++++-------- src/proto_alpha/lib_protocol/src/main.mli | 2 +- 8 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml index aaeef8ee8..33b40899e 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml @@ -41,7 +41,7 @@ let create_state ~preserved_levels = (* get the delegate that had the right to bake for a specific level/slot *) let fetch_baker (cctxt : #Proto_alpha.full) ~chain ~block = Alpha_block_services.metadata cctxt ~chain ~block () >>=? fun - { protocol_data = { Alpha_context.Block_header.baker } } -> + { protocol_data = { Apply_results.baker } } -> return baker (* We choose a previous offset (5 blocks from head) to ensure that the diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index ea1b209a0..a8ed8239e 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -738,12 +738,6 @@ module Block_header : sig type raw = Block_header.t type shell_header = Block_header.shell_header - type metadata = { - baker: Signature.Public_key_hash.t ; - level: Level.t ; - voting_period_kind: Voting_period.kind ; - } - val raw: block_header -> raw val hash: block_header -> Block_hash.t @@ -755,7 +749,6 @@ module Block_header : sig val unsigned_encoding: (shell_header * contents) Data_encoding.t val protocol_data_encoding: protocol_data Data_encoding.encoding val shell_header_encoding: shell_header Data_encoding.encoding - val metadata_encoding: metadata Data_encoding.encoding val max_header_length: int (** The maximum size of block headers in bytes *) diff --git a/src/proto_alpha/lib_protocol/src/apply_results.ml b/src/proto_alpha/lib_protocol/src/apply_results.ml index e2e3a5e58..3821aa906 100644 --- a/src/proto_alpha/lib_protocol/src/apply_results.ml +++ b/src/proto_alpha/lib_protocol/src/apply_results.ml @@ -987,3 +987,22 @@ let operation_data_and_metadata_encoding = (fun (Contents_list contents, signature) -> (Operation_data { contents ; signature }, No_operation_metadata)) ] + +type block_metadata = { + baker: Signature.Public_key_hash.t ; + level: Level.t ; + voting_period_kind: Voting_period.kind ; +} + +let block_metadata_encoding = + let open Data_encoding in + def "block_header.alpha.metadata" @@ + conv + (fun { baker ; level ; voting_period_kind} -> + (baker, level, voting_period_kind)) + (fun (baker, level, voting_period_kind) -> + { baker ; level ; voting_period_kind}) + (obj3 + (req "baker" Signature.Public_key_hash.encoding) + (req "level" Level.encoding) + (req "voting_period_kind" Voting_period.kind_encoding)) diff --git a/src/proto_alpha/lib_protocol/src/apply_results.mli b/src/proto_alpha/lib_protocol/src/apply_results.mli index a16ae57d1..43852c38c 100644 --- a/src/proto_alpha/lib_protocol/src/apply_results.mli +++ b/src/proto_alpha/lib_protocol/src/apply_results.mli @@ -144,3 +144,10 @@ val unpack_contents_list : type ('a, 'b) eq = Eq : ('a, 'a) eq val kind_equal_list : 'kind contents_list -> 'kind2 contents_result_list -> ('kind, 'kind2) eq option + +type block_metadata = { + baker: Signature.Public_key_hash.t ; + level: Level.t ; + voting_period_kind: Voting_period.kind ; +} +val block_metadata_encoding: block_metadata Data_encoding.encoding diff --git a/src/proto_alpha/lib_protocol/src/block_header_repr.ml b/src/proto_alpha/lib_protocol/src/block_header_repr.ml index fcff2f1d9..d48400275 100644 --- a/src/proto_alpha/lib_protocol/src/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/src/block_header_repr.ml @@ -82,24 +82,6 @@ let encoding = Block_header.shell_header_encoding protocol_data_encoding) -type metadata = { - baker: Signature.Public_key_hash.t ; - level: Level_repr.t ; - voting_period_kind: Voting_period_repr.kind ; -} -let metadata_encoding = - let open Data_encoding in - def "block_header.alpha.metadata" @@ - conv - (fun { baker ; level ; voting_period_kind } -> - (baker, level, voting_period_kind)) - (fun (baker, level, voting_period_kind) -> - { baker ; level ; voting_period_kind }) - (obj3 - (req "baker" Signature.Public_key_hash.encoding) - (req "level" Level_repr.encoding) - (req "voting_period_kind" Voting_period_repr.kind_encoding)) - (** Constants *) let max_header_length = diff --git a/src/proto_alpha/lib_protocol/src/block_header_repr.mli b/src/proto_alpha/lib_protocol/src/block_header_repr.mli index ee9f82ab3..8bebe69c9 100644 --- a/src/proto_alpha/lib_protocol/src/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/src/block_header_repr.mli @@ -28,12 +28,6 @@ type block_header = t type raw = Block_header.t type shell_header = Block_header.shell_header -type metadata = { - baker: Signature.Public_key_hash.t ; - level: Level_repr.t ; - voting_period_kind: Voting_period_repr.kind ; -} - val raw: block_header -> raw val encoding: block_header Data_encoding.encoding @@ -42,7 +36,6 @@ val contents_encoding: contents Data_encoding.t val unsigned_encoding: (Block_header.shell_header * contents) Data_encoding.t val protocol_data_encoding: protocol_data Data_encoding.encoding val shell_header_encoding: shell_header Data_encoding.encoding -val metadata_encoding: metadata Data_encoding.encoding val max_header_length: int (** The maximum size of block headers in bytes *) diff --git a/src/proto_alpha/lib_protocol/src/main.ml b/src/proto_alpha/lib_protocol/src/main.ml index 87950d5cb..e7dd9a137 100644 --- a/src/proto_alpha/lib_protocol/src/main.ml +++ b/src/proto_alpha/lib_protocol/src/main.ml @@ -17,8 +17,8 @@ type block_header = Alpha_context.Block_header.t = { let block_header_data_encoding = Alpha_context.Block_header.protocol_data_encoding -type block_header_metadata = Alpha_context.Block_header.metadata -let block_header_metadata_encoding = Alpha_context.Block_header.metadata_encoding +type block_header_metadata = Apply_results.block_metadata +let block_header_metadata_encoding = Apply_results.block_metadata_encoding type operation_data = Alpha_context.packed_protocol_data = | Operation_data : 'kind Alpha_context.Operation.protocol_data -> operation_data @@ -182,7 +182,7 @@ let apply_operation let finalize_block { mode ; ctxt ; op_count } = match mode with | Partial_construction _ -> - let level = Alpha_context. Level.current ctxt in + let level = Alpha_context.Level.current ctxt in Alpha_context.Vote.get_current_period_kind ctxt >>=? fun voting_period_kind -> let baker = Signature.Public_key_hash.zero in Signature.Public_key_hash.Map.fold @@ -192,14 +192,12 @@ let finalize_block { mode ; ctxt ; op_count } = (Alpha_context.get_deposits ctxt) (return ctxt) >>=? fun ctxt -> let ctxt = Alpha_context.finalize ctxt in - return (ctxt, { Alpha_context.Block_header.baker ; level ; - voting_period_kind }) + return (ctxt, Apply_results.{ baker ; level ; voting_period_kind }) | Partial_application { baker ; _ } -> let level = Alpha_context. Level.current ctxt in Alpha_context.Vote.get_current_period_kind ctxt >>=? fun voting_period_kind -> let ctxt = Alpha_context.finalize ctxt in - return (ctxt, { Alpha_context.Block_header.baker ; level ; - voting_period_kind }) + return (ctxt, Apply_results.{ baker ; level ; voting_period_kind }) | Application { baker ; block_header = { protocol_data = { contents = protocol_data ; _ } ; _ } } | Full_construction { protocol_data ; baker ; _ } -> @@ -214,7 +212,7 @@ let finalize_block { mode ; ctxt ; op_count } = raw_level fitness priority op_count in Alpha_context.Vote.get_current_period_kind ctxt >>=? fun voting_period_kind -> let ctxt = Alpha_context.finalize ~commit_message ctxt in - return (ctxt, { Alpha_context.Block_header.baker ; level ; voting_period_kind }) + return (ctxt, Apply_results.{ baker ; level ; voting_period_kind }) let compare_operations op1 op2 = let open Alpha_context in diff --git a/src/proto_alpha/lib_protocol/src/main.mli b/src/proto_alpha/lib_protocol/src/main.mli index a8be17c3d..083d230d3 100644 --- a/src/proto_alpha/lib_protocol/src/main.mli +++ b/src/proto_alpha/lib_protocol/src/main.mli @@ -43,7 +43,7 @@ type operation = Alpha_context.packed_operation = { include Updater.PROTOCOL with type block_header_data = Alpha_context.Block_header.protocol_data - and type block_header_metadata = Alpha_context.Block_header.metadata + and type block_header_metadata = Apply_results.block_metadata and type block_header = Alpha_context.Block_header.t and type operation_data := operation_data and type operation_receipt = Apply_results.packed_operation_metadata