Alpha: move block_metadata from alpha_context to apply_result

This commit is contained in:
Marco Stronati 2018-06-27 16:57:05 +02:00 committed by Benjamin Canou
parent 91d497fd4a
commit 4b282ea8c5
8 changed files with 34 additions and 42 deletions

View File

@ -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

View File

@ -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 *)

View File

@ -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))

View File

@ -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

View File

@ -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 =

View File

@ -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 *)

View File

@ -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
@ -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

View File

@ -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