Proto/Alpha: minor renaming

This commit is contained in:
Grégoire Henry 2017-04-20 15:21:10 +02:00
parent 565654a242
commit d06fcebd1f
15 changed files with 128 additions and 88 deletions

View File

@ -28,7 +28,7 @@ let rec compute_stamp
let rec loop () =
let proof_of_work_nonce = generate_proof_of_work_nonce () in
let unsigned_header =
Tezos_context.Block.forge_header
Tezos_context.Block_header.forge_unsigned
shell { priority ; seed_nonce_hash ; proof_of_work_nonce } in
let signed_header =
Ed25519.Signature.append delegate_sk unsigned_header in
@ -51,7 +51,7 @@ let inject_block cctxt block
Operation_list_list_hash.compute
(List.map Operation_list_hash.compute (List.map (List.map (function Client_node_rpcs.Blob op -> Tezos_data.Operation.hash op | Hash oph -> oph)) operations)) in
let shell =
{ Block_header.net_id = bi.net_id ; level = bi.level ;
{ Tezos_data.Block_header.net_id = bi.net_id ; level = bi.level ;
proto_level = bi.proto_level ;
predecessor = bi.hash ; timestamp ; fitness ; operations_hash } in
compute_stamp cctxt block

View File

@ -273,7 +273,7 @@ module Helpers = struct
let block cctxt block shell proto =
call_error_service1 cctxt
Services.Helpers.Parse.block block
({ shell ; proto } : Block_header.t)
({ shell ; proto } : Block_header.raw)
end
end

View File

@ -353,7 +353,7 @@ module Helpers : sig
val block:
Client_rpcs.config ->
block -> Block_header.shell_header -> MBytes.t ->
Block.proto_header tzresult Lwt.t
Block_header.proto_header tzresult Lwt.t
end
end

View File

@ -21,7 +21,7 @@
"Roll_repr",
"Vote_repr",
"Operation_repr",
"Block_repr",
"Block_header_repr",
"Storage_sigs",
"Storage_functors",

View File

@ -261,7 +261,7 @@ let begin_application ctxt block pred_timestamp =
let finalize_application ctxt block miner =
(* end of level (from this point nothing should fail) *)
let priority = block.Block.proto.priority in
let priority = block.Block_header.proto.priority in
let reward = Mining.base_mining_reward ctxt ~priority in
Nonce.record_hash ctxt
miner reward block.proto.seed_nonce_hash >>=? fun ctxt ->

View File

@ -12,7 +12,7 @@ open Tezos_hash
(** Block header *)
(** Exported type *)
type header = {
type t = {
shell: Block_header.shell_header ;
proto: proto_header ;
signature: Ed25519.Signature.t ;
@ -24,6 +24,14 @@ and proto_header = {
proof_of_work_nonce: MBytes.t ;
}
type block_header = t
type raw = Tezos_data.Block_header.t
type shell_header = Tezos_data.Block_header.shell_header
let raw_encoding = Tezos_data.Block_header.encoding
let shell_header_encoding = Tezos_data.Block_header.shell_header_encoding
let proto_header_encoding =
let open Data_encoding in
conv
@ -49,6 +57,17 @@ let unsigned_header_encoding =
Block_header.shell_header_encoding
proto_header_encoding
let encoding =
let open Data_encoding in
conv
(fun { shell ; proto ; signature } ->
(shell, (proto, signature)))
(fun (shell, (proto, signature)) ->
{ shell ; proto ; signature })
(merge_objs
Block_header.shell_header_encoding
signed_proto_header_encoding)
(** Constants *)
let max_header_length =
@ -61,10 +80,10 @@ let max_header_length =
type error +=
| Cant_parse_proto_header
let parse_header
let parse
({ shell = { net_id ; level ; proto_level ; predecessor ;
timestamp ; fitness ; operations_hash } ;
proto } : Block_header.t) : header tzresult =
proto } : Block_header.t) : block_header tzresult =
match Data_encoding.Binary.of_bytes signed_proto_header_encoding proto with
| None -> Error [Cant_parse_proto_header]
| Some (proto, signature) ->
@ -73,5 +92,14 @@ let parse_header
timestamp ; fitness ; operations_hash } in
Ok { shell ; proto ; signature }
let forge_header shell proto =
let forge_unsigned shell proto =
Data_encoding.Binary.to_bytes unsigned_header_encoding (shell, proto)
let hash_raw = Block_header.hash
let hash { shell ; proto ; signature } =
Block_header.hash
{ shell ;
proto =
Data_encoding.Binary.to_bytes
signed_proto_header_encoding
(proto, signature ) }

View File

@ -10,7 +10,7 @@
open Tezos_hash
(** Exported type *)
type header = {
type t = {
shell: Block_header.shell_header ;
proto: proto_header ;
signature: Ed25519.Signature.t ;
@ -22,21 +22,28 @@ and proto_header = {
proof_of_work_nonce: MBytes.t ;
}
(** The maximum size of block headers in bytes *)
type block_header = t
type raw = Tezos_data.Block_header.t
type shell_header = Tezos_data.Block_header.shell_header
val encoding: block_header Data_encoding.encoding
val raw_encoding: raw Data_encoding.t
val proto_header_encoding: proto_header Data_encoding.encoding
val shell_header_encoding: shell_header Data_encoding.encoding
val max_header_length: int
(** The maximum size of block headers in bytes *)
val parse: Block_header.t -> block_header tzresult
(** Parse the protocol-specific part of a block header. *)
val parse_header: Block_header.t -> header tzresult
val proto_header_encoding:
proto_header Data_encoding.encoding
val unsigned_header_encoding:
(Block_header.shell_header * proto_header) Data_encoding.encoding
val forge_header:
val forge_unsigned:
Block_header.shell_header -> proto_header -> MBytes.t
(** [forge_header shell_hdr proto_hdr] is the binary serialization
(using [unsigned_header_encoding]) of a block header,
comprising both the shell and the protocol part of the header,
without the signature. *)
val hash: block_header -> Block_hash.t
val hash_raw: raw -> Block_hash.t

View File

@ -20,12 +20,12 @@ let max_number_of_operations =
Tezos_context.Constants.max_number_of_operations
let max_block_length =
Tezos_context.Block.max_header_length
Tezos_context.Block_header.max_header_length
let rpc_services = Services_registration.rpc_services
type validation_mode =
| Application of Tezos_context.Block.header * Tezos_context.public_key_hash
| Application of Tezos_context.Block_header.t * Tezos_context.public_key_hash
| Construction of { pred_block : Block_hash.t ; timestamp : Time.t }
type validation_state =
@ -40,7 +40,7 @@ let precheck_block
~ancestor_context:_
~ancestor_timestamp:_
raw_block =
Lwt.return (Tezos_context.Block.parse_header raw_block) >>=? fun _ ->
Lwt.return (Tezos_context.Block_header.parse raw_block) >>=? fun _ ->
(* TODO: decide what other properties should be checked *)
return ()
@ -49,7 +49,7 @@ let begin_application
~predecessor_timestamp:pred_timestamp
~predecessor_fitness:pred_fitness
raw_block =
Lwt.return (Tezos_context.Block.parse_header raw_block) >>=? fun header ->
Lwt.return (Tezos_context.Block_header.parse raw_block) >>=? fun header ->
let level = header.shell.level in
let fitness = pred_fitness in
let timestamp = header.shell.timestamp in

View File

@ -118,14 +118,14 @@ let check_timestamp c priority pred_timestamp =
fail_unless Timestamp.(minimal_time <= timestamp)
(Timestamp_too_early (minimal_time, timestamp))
let check_mining_rights c { Block.proto = { priority } }
let check_mining_rights c { Block_header.proto = { priority } }
pred_timestamp =
let level = Level.current c in
Roll.mining_rights_owner c level ~priority >>=? fun delegate ->
check_timestamp c priority pred_timestamp >>=? fun () ->
return delegate
let pay_mining_bond c { Block.proto = { priority } } id =
let pay_mining_bond c { Block_header.proto = { priority } } id =
if Compare.Int.(priority >= Constants.first_free_mining_slot c)
then return c
else
@ -216,13 +216,8 @@ let check_hash hash stamp_threshold =
let word = String.get_int64 bytes 0 in
Compare.Uint64.(word < stamp_threshold)
let check_header_hash {Block.shell;proto;signature} stamp_threshold =
let hash =
Block_hash.hash_bytes [
Data_encoding.Binary.to_bytes
(Data_encoding.tup2
Block.unsigned_header_encoding Ed25519.Signature.encoding)
((shell, proto), signature)] in
let check_header_hash header stamp_threshold =
let hash = Block_header.hash header in
check_hash hash stamp_threshold
type error +=
@ -238,8 +233,8 @@ let check_proof_of_work_stamp ctxt block =
let check_signature ctxt block id =
Public_key.get ctxt id >>=? fun key ->
let check_signature key { Block.proto ; shell ; signature } =
let unsigned_header = Block.forge_header shell proto in
let check_signature key { Block_header.proto ; shell ; signature } =
let unsigned_header = Block_header.forge_unsigned shell proto in
Ed25519.Signature.check key signature unsigned_header in
if check_signature key block then
return ()
@ -250,7 +245,7 @@ let max_fitness_gap ctxt =
let slots = Int64.of_int (Constants.max_signing_slot ctxt + 1) in
Int64.add slots 1L
let check_fitness_gap ctxt (block : Block.header) =
let check_fitness_gap ctxt (block : Block_header.t) =
let current_fitness = Fitness.current ctxt in
Lwt.return (Fitness.to_int64 block.shell.fitness) >>=? fun announced_fitness ->
let gap = Int64.sub announced_fitness current_fitness in

View File

@ -29,7 +29,7 @@ val minimal_time: context -> int -> Time.t -> Time.t tzresult Lwt.t
val pay_mining_bond:
context ->
Block.header ->
Block_header.t ->
public_key_hash ->
context tzresult Lwt.t
@ -42,7 +42,7 @@ val pay_endorsement_bond:
* the bond have been payed if the slot is below [Constants.first_free_mining_slot].
*)
val check_mining_rights:
context -> Block.header -> Time.t -> public_key_hash tzresult Lwt.t
context -> Block_header.t -> Time.t -> public_key_hash tzresult Lwt.t
(** [check_signing_rights c slot contract] verifies that:
* the slot is valid;
@ -85,13 +85,13 @@ val first_endorsement_slots:
Level.t -> int list tzresult Lwt.t
val check_signature:
context -> Block.header -> public_key_hash -> unit tzresult Lwt.t
context -> Block_header.t -> public_key_hash -> unit tzresult Lwt.t
val check_hash: Block_hash.t -> int64 -> bool
val check_proof_of_work_stamp:
context -> Block.header -> unit tzresult Lwt.t
context -> Block_header.t -> unit tzresult Lwt.t
val check_fitness_gap:
context -> Block.header -> unit tzresult Lwt.t
context -> Block_header.t -> unit tzresult Lwt.t
val dawn_of_a_new_cycle: context -> Cycle.t option tzresult Lwt.t

View File

@ -619,8 +619,8 @@ module Helpers = struct
let block custom_root =
RPC.service
~description:"Parse a block"
~input: Block_header.encoding
~output: (wrap_tzerror Block.proto_header_encoding)
~input: Block_header.raw_encoding
~output: (wrap_tzerror Block_header.proto_header_encoding)
RPC.Path.(custom_root / "helpers" / "parse" / "block" )
end

View File

@ -11,7 +11,7 @@ open Tezos_context
type rpc_context = {
block_hash: Block_hash.t ;
block_header: Block_header.t ;
block_header: Block_header.raw ;
operation_hashes: unit -> Operation_hash.t list list Lwt.t ;
operations: unit -> Operation.raw list list Lwt.t ;
context: Tezos_context.t ;
@ -474,7 +474,7 @@ let forge_block _ctxt
((net_id, predecessor, timestamp, fitness, operations_hash),
(level, priority, proto_level, seed_nonce_hash, proof_of_work_nonce)) : MBytes.t tzresult Lwt.t =
let level = Raw_level.to_int32 level in
return (Block.forge_header
return (Block_header.forge_unsigned
{ net_id ; level ; proto_level ; predecessor ;
timestamp ; fitness ; operations_hash }
{ priority ; seed_nonce_hash ; proof_of_work_nonce })
@ -521,7 +521,7 @@ let parse_operations ctxt (operations, check) =
let () = register1 Services.Helpers.Parse.operations parse_operations
let parse_block _ctxt raw_block =
Lwt.return (Block.parse_header raw_block) >>=? fun { proto } ->
Lwt.return (Block_header.parse raw_block) >>=? fun { proto } ->
return proto
let () = register1 Services.Helpers.Parse.block parse_block

View File

@ -30,7 +30,7 @@ module Operation = struct
type t = operation
include Operation_repr
end
module Block = Block_repr
module Block_header = Block_header_repr
module Vote = struct
include Vote_repr
include Vote_storage

View File

@ -529,9 +529,9 @@ module Operation : sig
end
module Block : sig
module Block_header : sig
type header = {
type t = {
shell: Block_header.shell_header ;
proto: proto_header ;
signature: Ed25519.Signature.t ;
@ -543,18 +543,31 @@ module Block : sig
proof_of_work_nonce: MBytes.t ;
}
type block_header = t
type raw = Tezos_data.Block_header.t
type shell_header = Tezos_data.Block_header.shell_header
val hash: block_header -> Block_hash.t
val hash_raw: raw -> Block_hash.t
val encoding: block_header Data_encoding.encoding
val raw_encoding: raw Data_encoding.t
val proto_header_encoding: proto_header Data_encoding.encoding
val shell_header_encoding: shell_header Data_encoding.encoding
val max_header_length: int
(** The maximum size of block headers in bytes *)
val parse_header: Block_header.t -> header tzresult
val parse: Block_header.t -> block_header tzresult
(** Parse the protocol-specific part of a block header. *)
val proto_header_encoding:
proto_header Data_encoding.encoding
val unsigned_header_encoding:
(Block_header.shell_header * proto_header) Data_encoding.encoding
val forge_header:
val forge_unsigned:
Block_header.shell_header -> proto_header -> MBytes.t
(** [forge_header shell_hdr proto_hdr] is the binary serialization
(using [unsigned_header_encoding]) of a block header,
comprising both the shell and the protocol part of the header,
without the signature. *)
end

View File

@ -21,7 +21,7 @@ let rpc_config : Client_rpcs.config = {
}
let dictator_sk =
Environment.Ed25519.Secret_key.of_b58check_exn
Ed25519.Secret_key.of_b58check_exn
"edskRhxswacLW6jF6ULavDdzwqnKJVS4UcDTNiCyiH6H8ZNnn2pmNviL7\
pRNz9kRxxaWQFzEQEcZExGHKbwmuaAcoMegj5T99z"
@ -57,7 +57,6 @@ module Account = struct
}
let encoding =
let open Environment.Ed25519 in
let open Data_encoding in
conv
(fun { alias ; sk ; pk ; pkh ; contract } ->
@ -67,9 +66,9 @@ module Account = struct
{ alias ; sk ; pk ; pkh ; contract })
(obj5
(req "alias" string)
(req "sk" Secret_key.encoding)
(req "pk" Public_key.encoding)
(req "pkh" Public_key_hash.encoding)
(req "sk" Ed25519.Secret_key.encoding)
(req "pk" Ed25519.Public_key.encoding)
(req "pkh" Ed25519.Public_key_hash.encoding)
(req "contract" Contract.encoding))
let pp_account ppf account =
@ -80,7 +79,7 @@ module Account = struct
let sk, pk = match keys with
| Some keys -> keys
| None -> Sodium.Sign.random_keypair () in
let pkh = Environment.Ed25519.Public_key.hash pk in
let pkh = Ed25519.Public_key.hash pk in
let contract = Contract.default_contract pkh in
{ alias ; contract ; pkh ; pk ; sk }
@ -92,7 +91,6 @@ module Account = struct
}
let destination_encoding =
let open Environment.Ed25519 in
let open Data_encoding in
conv
(fun { alias ; pk ; pkh ; contract } ->
@ -101,8 +99,8 @@ module Account = struct
{ alias ; pk ; pkh ; contract })
(obj4
(req "alias" string)
(req "pk" Public_key.encoding)
(req "pkh" Public_key_hash.encoding)
(req "pk" Ed25519.Public_key.encoding)
(req "pkh" Ed25519.Public_key_hash.encoding)
(req "contract" Contract.encoding))
let pp_destination ppf destination =
@ -110,53 +108,52 @@ module Account = struct
Format.fprintf ppf "%s" (Data_encoding_ezjsonm.to_string json)
let create_destination ~alias ~contract ~pk =
let pkh = Environment.Ed25519.Public_key.hash pk in
let pkh = Ed25519.Public_key.hash pk in
{ alias ; contract ; pk ; pkh }
type bootstrap_accounts = { b1 : t ; b2 : t ; b3 : t ; b4 : t ; b5 : t ; }
let bootstrap_accounts =
let open Environment.Ed25519 in
let bootstrap1_pk =
Public_key.of_b58check_exn
Ed25519.Public_key.of_b58check_exn
"edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" in
let bootstrap2_pk =
Public_key.of_b58check_exn
Ed25519.Public_key.of_b58check_exn
"edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9" in
let bootstrap3_pk =
Public_key.of_b58check_exn
Ed25519.Public_key.of_b58check_exn
"edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV" in
let bootstrap4_pk =
Public_key.of_b58check_exn
Ed25519.Public_key.of_b58check_exn
"edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU" in
let bootstrap5_pk =
Public_key.of_b58check_exn
Ed25519.Public_key.of_b58check_exn
"edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n" in
let bootstrap1_sk =
Secret_key.of_b58check_exn
Ed25519.Secret_key.of_b58check_exn
"edskRuR1azSfboG86YPTyxrQgosh5zChf5bVDmptqLTb5EuXAm9\
rsnDYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi" in
let bootstrap2_sk =
Secret_key.of_b58check_exn
Ed25519.Secret_key.of_b58check_exn
"edskRkJz4Rw2rM5NtabEWMbbg2bF4b1nfFajaqEuEk4SgU7eeDby\
m9gVQtBTbYo32WUg2zb5sNBkD1whRN7zX43V9bftBbtaKc" in
let bootstrap3_sk =
Secret_key.of_b58check_exn
Ed25519.Secret_key.of_b58check_exn
"edskS3qsqsNgdjUqeMsVcEwBn8dkZ5iDRz6aF21KhcCtRiAkWByp\
USbicccR4Vgqm9UdW2Vabuos6seezqgbXTrmcbLUG4rdAC" in
let bootstrap4_sk =
Secret_key.of_b58check_exn
Ed25519.Secret_key.of_b58check_exn
"edskRg9qcPqaVQa6jXWNMU5p71tseSuR7NzozgqZ9URsVDi81wTyP\
JdFSBdeakobyHUi4Xgu61jgKRQvkhXrPmEdEUfiqfiJFL" in
let bootstrap5_sk =
Secret_key.of_b58check_exn
Ed25519.Secret_key.of_b58check_exn
"edskS7rLN2Df3nbS1EYvwJbWo4umD7yPM1SUeX7gp1WhCVpMFXjcC\
yM58xs6xsnTsVqHQmJQ2RxoAjJGedWfvFmjQy6etA3dgZ" in
let cpt = ref 0 in
match List.map begin fun (pk, sk) ->
incr cpt ;
let alias = Printf.sprintf "bootstrap%d" !cpt in
let pkh = Environment.Ed25519.Public_key.hash pk in
let pkh = Ed25519.Public_key.hash pk in
{ alias ; contract = Contract.default_contract pkh; pkh ; pk ; sk }
end [
bootstrap1_pk, bootstrap1_sk;
@ -256,7 +253,7 @@ module Protocol = struct
~period:next_level.voting_period
~proposals
() >>=? fun bytes ->
let signed_bytes = Environment.Ed25519.Signature.append sk bytes in
let signed_bytes = Ed25519.Signature.append sk bytes in
return (Tezos_data.Operation.of_bytes_exn signed_bytes)
let ballot ?(block = `Prevalidation) ~src:({ pk; sk } : Account.t) ~proposal ballot =
@ -269,7 +266,7 @@ module Protocol = struct
~proposal
~ballot
() >>=? fun bytes ->
let signed_bytes = Environment.Ed25519.Signature.append sk bytes in
let signed_bytes = Ed25519.Signature.append sk bytes in
return (Tezos_data.Operation.of_bytes_exn signed_bytes)
end
@ -284,11 +281,11 @@ module Assert = struct
match pkh1, pkh2 with
| None, None -> true
| Some pkh1, Some pkh2 ->
Environment.Ed25519.Public_key_hash.equal pkh1 pkh2
Ed25519.Public_key_hash.equal pkh1 pkh2
| _ -> false in
let prn = function
| None -> "none"
| Some pkh -> Environment.Ed25519.Public_key_hash.to_hex pkh in
| Some pkh -> Ed25519.Public_key_hash.to_hex pkh in
Assert.equal ?msg ~prn ~eq pkh1 pkh2
let equal_tez ?msg tz1 tz2 =
@ -421,10 +418,10 @@ module Mining = struct
let proof_of_work_nonce =
Sodium.Random.Bigbytes.generate Constants.proof_of_work_nonce_size in
let unsigned_header =
Block.forge_header
Block_header.forge_unsigned
shell { priority ; seed_nonce_hash ; proof_of_work_nonce } in
let signed_header =
Environment.Ed25519.Signature.append delegate_sk unsigned_header in
Ed25519.Signature.append delegate_sk unsigned_header in
let block_hash = Block_hash.hash_bytes [signed_header] in
if Mining.check_hash block_hash stamp_threshold then
proof_of_work_nonce
@ -452,7 +449,7 @@ module Mining = struct
Operation_list_list_hash.compute
[Operation_list_hash.compute operation_hashes] in
let shell =
{ Block_header.net_id = bi.net_id ; predecessor = bi.hash ;
{ Tezos_data.Block_header.net_id = bi.net_id ; predecessor = bi.hash ;
timestamp ; fitness ; operations_hash ;
level = Raw_level.to_int32 level.level ;
proto_level } in
@ -471,7 +468,7 @@ module Mining = struct
~seed_nonce_hash
~proof_of_work_nonce
() >>=? fun unsigned_header ->
let signed_header = Environment.Ed25519.Signature.append src_sk unsigned_header in
let signed_header = Ed25519.Signature.append src_sk unsigned_header in
Client_node_rpcs.inject_block rpc_config
?force signed_header
[List.map (fun h -> Client_node_rpcs.Blob h) operations] >>=? fun block_hash ->
@ -535,7 +532,7 @@ module Endorse = struct
~block:hash
~slot:slot
() >>=? fun bytes ->
let signed_bytes = Environment.Ed25519.Signature.append src_sk bytes in
let signed_bytes = Ed25519.Signature.append src_sk bytes in
return (Tezos_data.Operation.of_bytes_exn signed_bytes)
let signing_slots