diff --git a/src/client/embedded/bootstrap/client_proto_rpcs.ml b/src/client/embedded/bootstrap/client_proto_rpcs.ml index 6fc2c0810..5649310d8 100644 --- a/src/client/embedded/bootstrap/client_proto_rpcs.ml +++ b/src/client/embedded/bootstrap/client_proto_rpcs.ml @@ -235,10 +235,10 @@ module Helpers = struct block ~net ~level ~nonce () = operations block ~net [Seed_nonce_revelation { level ; nonce }] end - let block_header + let block block ~net ~predecessor ~timestamp ~fitness ~operations ~level ~priority ~seed_nonce_hash ~proof_of_work_nonce () = - call_error_service1 Services.Helpers.Forge.block_header block + call_error_service1 Services.Helpers.Forge.block block (net, predecessor, timestamp, fitness, operations, level, priority, seed_nonce_hash, proof_of_work_nonce) end diff --git a/src/client/embedded/bootstrap/client_proto_rpcs.mli b/src/client/embedded/bootstrap/client_proto_rpcs.mli index 095707df5..0cbff7de6 100644 --- a/src/client/embedded/bootstrap/client_proto_rpcs.mli +++ b/src/client/embedded/bootstrap/client_proto_rpcs.mli @@ -197,7 +197,7 @@ module Helpers : sig nonce:Nonce.t -> unit -> MBytes.t tzresult Lwt.t end - val block_header: + val block: block -> net:net -> predecessor:Block_hash.t -> diff --git a/src/client/embedded/bootstrap/mining/client_mining_forge.ml b/src/client/embedded/bootstrap/mining/client_mining_forge.ml index fdee8d753..15f73d4c4 100644 --- a/src/client/embedded/bootstrap/mining/client_mining_forge.ml +++ b/src/client/embedded/bootstrap/mining/client_mining_forge.ml @@ -48,7 +48,7 @@ let inject_block block let slot = level.level, Int32.of_int priority in compute_stamp block src_sk shell slot seed_nonce_hash >>=? fun proof_of_work_nonce -> - Client_proto_rpcs.Helpers.Forge.block_header + Client_proto_rpcs.Helpers.Forge.block block ~net:bi.net ~predecessor:bi.hash diff --git a/src/node/db/context.mli b/src/node/db/context.mli index db9997ba9..fed540f02 100644 --- a/src/node/db/context.mli +++ b/src/node/db/context.mli @@ -32,9 +32,9 @@ include Persist.STORE with type t = store exception Preexistent_context of string * Block_hash.t val exists: index -> Block_hash.t -> bool Lwt.t -val commit: index -> Store.block_header -> Block_hash.t -> store -> unit Lwt.t +val commit: index -> Store.block -> Block_hash.t -> store -> unit Lwt.t val commit_invalid: - index -> Store.block_header -> Block_hash.t -> error list -> unit Lwt.t + index -> Store.block -> Block_hash.t -> error list -> unit Lwt.t val checkout: index -> Block_hash.t -> store tzresult option Lwt.t exception Invalid_context of error list val checkout_exn: index -> Block_hash.t -> store Lwt.t diff --git a/src/node/db/store.ml b/src/node/db/store.ml index 24fcd0c0d..4ffc3abd1 100644 --- a/src/node/db/store.ml +++ b/src/node/db/store.ml @@ -214,15 +214,15 @@ include Data_store (*-- Typed block store under "blocks/" ---------------------------------------*) -type shell_block_header = { +type shell_block = { net_id: net_id ; predecessor: Block_hash.t ; timestamp: Time.t ; fitness: MBytes.t list ; operations: Operation_hash.t list ; } -type block_header = { - shell: shell_block_header ; +type block = { + shell: shell_block ; proto: MBytes.t ; } @@ -235,7 +235,7 @@ let net_id_encoding = let pp_net_id ppf (Net id) = Block_hash.pp_short ppf id -let shell_block_header_encoding = +let shell_block_encoding = let open Data_encoding in conv (fun { net_id ; predecessor ; timestamp ; fitness ; operations } -> @@ -249,29 +249,29 @@ let shell_block_header_encoding = (req "fitness" Fitness.encoding) (req "operations" (list Operation_hash.encoding))) -let block_header_encoding = +let block_encoding = let open Data_encoding in conv (fun { shell ; proto } -> (shell, proto)) (fun (shell, proto) -> { shell ; proto }) (merge_objs - shell_block_header_encoding + shell_block_encoding (obj1 (req "data" Variable.bytes))) module Raw_block_value = struct - type t = block_header + type t = block let to_bytes v = - Data_encoding.Binary.to_bytes block_header_encoding v + Data_encoding.Binary.to_bytes block_encoding v let of_bytes b = - Data_encoding.Binary.of_bytes block_header_encoding b + Data_encoding.Binary.of_bytes block_encoding b end -module Block_header_key = struct +module Block_key = struct type t = Block_hash.t let to_path p = "blocks" :: Block_hash.to_path p @ [ "contents" ] end -module Block_header = Make (Block_header_key) (Raw_block_value) -module Raw_block = Make (Block_header_key) (Raw_value) +module Parsed_block = Make (Block_key) (Raw_block_value) +module Raw_block = Make (Block_key) (Raw_value) module Block_pred_key = struct type t = Block_hash.t @@ -295,13 +295,13 @@ module Block = struct type t = FS.t type key = Block_hash.t type value = Block_hash.t * - block_header Time.timed_data option Lwt.t Lazy.t + block Time.timed_data option Lwt.t Lazy.t let mem = Block_pred.mem let full_get s k = Block_time.get s k >>= function | None -> Lwt.return_none | Some time -> - Block_header.get s k >>= function + Parsed_block.get s k >>= function | None -> Lwt.return_none | Some data -> Lwt.return (Some { Time.data ; time }) let get s k = @@ -318,14 +318,14 @@ module Block = struct r >>= function | None -> Lwt.return_unit | Some { Time.data ; time } -> - Block_header.set s k data >>= fun () -> + Parsed_block.set s k data >>= fun () -> Block_time.set s k time let full_set s k r = set s k (r.Time.data.shell.predecessor, Lazy.from_val (Lwt.return (Some r))) let del s k = Block_pred.del s k >>= fun () -> Block_time.del s k >>= fun () -> - Block_header.del s k + Parsed_block.del s k let compare b1 b2 = let (>>) x y = if x = 0 then y () else x in diff --git a/src/node/db/store.mli b/src/node/db/store.mli index e85d85a62..a91909889 100644 --- a/src/node/db/store.mli +++ b/src/node/db/store.mli @@ -93,41 +93,41 @@ val shell_operation_encoding: shell_operation Data_encoding.t val operation_encoding: operation Data_encoding.t (** Raw blocks in the database (partially parsed). *) -type shell_block_header = { +type shell_block = { net_id: net_id ; predecessor: Block_hash.t ; timestamp: Time.t ; fitness: MBytes.t list ; operations: Operation_hash.t list ; } -type block_header = { - shell: shell_block_header ; +type block = { + shell: shell_block ; proto: MBytes.t ; } -val shell_block_header_encoding: shell_block_header Data_encoding.t -val block_header_encoding: block_header Data_encoding.t +val shell_block_encoding: shell_block Data_encoding.t +val block_encoding: block Data_encoding.t (** {2 Block and operations store} ********************************************) module Block : sig - val of_bytes: MBytes.t -> block_header option - val to_bytes: block_header -> MBytes.t - val hash: block_header -> Block_hash.t + val of_bytes: MBytes.t -> block option + val to_bytes: block -> MBytes.t + val hash: block -> Block_hash.t include TYPED_IMPERATIVE_STORE with type t = block_store and type key = Block_hash.t and type value = - Block_hash.t * block_header Time.timed_data option Lwt.t Lazy.t + Block_hash.t * block Time.timed_data option Lwt.t Lazy.t - val compare: block_header -> block_header -> int - val equal: block_header -> block_header -> bool + val compare: block -> block -> int + val equal: block -> block -> bool val raw_get: t -> Block_hash.t -> MBytes.t option Lwt.t - val full_get: t -> Block_hash.t -> block_header Time.timed_data option Lwt.t + val full_get: t -> Block_hash.t -> block Time.timed_data option Lwt.t - val full_set: t -> Block_hash.t -> block_header Time.timed_data -> unit Lwt.t + val full_set: t -> Block_hash.t -> block Time.timed_data -> unit Lwt.t end diff --git a/src/node/shell/messages.ml b/src/node/shell/messages.ml index a1942f2d7..eba85a1a0 100644 --- a/src/node/shell/messages.ml +++ b/src/node/shell/messages.ml @@ -16,8 +16,8 @@ type message = | Discover_blocks of net_id * Block_hash.t list (* Block locator *) | Block_inventory of net_id * Block_hash.t list - | Get_block_headers of Block_hash.t list - | Block_header of MBytes.t + | Get_blocks of Block_hash.t list + | Block of MBytes.t | Current_operations of net_id | Operation_inventory of net_id * Operation_hash.t list @@ -40,9 +40,9 @@ let to_frame msg = [ S 2100 ; bh netid ; F (List.map bh blocks) ] | Block_inventory (Net netid, blocks) -> [ S 2101 ; bh netid ; F (List.map bh blocks) ] - | Get_block_headers blocks -> + | Get_blocks blocks -> [ S 2102 ; F (List.map bh blocks) ] - | Block_header b -> + | Block b -> [ S 2103 ; B b ] | Current_operations (Net net_id) -> @@ -72,8 +72,8 @@ let from_frame msg = | [ S 2101 ; B netid ; F blocks ] -> Some (Block_inventory (net netid, List.map bh blocks)) | [ S 2102 ; F blocks ] -> - Some (Get_block_headers (List.map bh blocks)) - | [ S 2103 ; B bh ] -> Some (Block_header bh) + Some (Get_blocks (List.map bh blocks)) + | [ S 2103 ; B bh ] -> Some (Block bh) | [ S 2700 ; B netid ] -> Some (Current_operations (net netid)) | [ S 2701 ; B netid ; F ops ] -> diff --git a/src/node/shell/messages.mli b/src/node/shell/messages.mli index ee4a96b20..0f8c1601a 100644 --- a/src/node/shell/messages.mli +++ b/src/node/shell/messages.mli @@ -13,8 +13,8 @@ type message = | Discover_blocks of Store.net_id * Block_hash.t list (* Block locator *) | Block_inventory of Store.net_id * Block_hash.t list - | Get_block_headers of Block_hash.t list - | Block_header of MBytes.t + | Get_blocks of Block_hash.t list + | Block of MBytes.t | Current_operations of Store.net_id | Operation_inventory of Store.net_id * Operation_hash.t list diff --git a/src/node/shell/node.ml b/src/node/shell/node.ml index 0956192c8..f14d5e1b7 100644 --- a/src/node/shell/node.ml +++ b/src/node/shell/node.ml @@ -98,16 +98,16 @@ let process state validator msg = State.Block.prefetch state net_id blocks ; Lwt.return_nil - | Get_block_headers blocks -> - lwt_log_info "process Get_block_headers" >>= fun () -> + | Get_blocks blocks -> + lwt_log_info "process Get_blocks" >>= fun () -> Lwt_list.map_p (State.Block.raw_read state) blocks >>= fun blocks -> let cons_block acc = function - | Some b -> Block_header b :: acc + | Some b -> Block b :: acc | None -> acc in Lwt.return (List.fold_left cons_block [] blocks) - | Block_header block -> - lwt_log_info "process Block_header" >>= fun () -> + | Block block -> + lwt_log_info "process Block" >>= fun () -> process_block state validator block >>= fun _ -> Lwt.return_nil @@ -182,7 +182,7 @@ let request_operations net _net_id operations = let request_blocks net _net_id blocks = (* TODO improve the lookup strategy. For now simply broadcast the request to all our neighbours. *) - P2p.broadcast (Messages.(to_frame (Get_block_headers blocks))) net + P2p.broadcast (Messages.(to_frame (Get_blocks blocks))) net let init_p2p net_params = match net_params with diff --git a/src/node/shell/state.ml b/src/node/shell/state.ml index 68ff5bb8b..b4433eb6e 100644 --- a/src/node/shell/state.ml +++ b/src/node/shell/state.ml @@ -78,7 +78,7 @@ type t = { nets: net Block_hash_table.t ; store: Store.store ; block_db: Db_proxy.Block.t ; - block_watchers: (Block_hash.t * Store.block_header) Watcher.t list ref ; + block_watchers: (Block_hash.t * Store.block) Watcher.t list ref ; operation_db: Db_proxy.Operation.t ; operation_watchers: (Operation_hash.t * Store.operation) Watcher.t list ref ; @@ -297,14 +297,14 @@ let iter_predecessors module Block = struct - type shell_header = Store.shell_block_header = { + type shell_header = Store.shell_block = { net_id: net_id ; predecessor: Block_hash.t ; timestamp: Time.t ; fitness: MBytes.t list ; operations: Operation_hash.t list ; } - type t = Store.block_header = { + type t = Store.block = { shell: shell_header ; proto: MBytes.t ; } @@ -341,7 +341,7 @@ module Block = struct block >>= function | None -> assert false | Some block -> Lwt.return block - let db_store db k (v: Store.block_header) = + let db_store db k (v: Store.block) = Db_proxy.Block.store db k (v.shell.predecessor, lazy (Lwt.return (Some (Time.make_timed v)))) let store t bytes = diff --git a/src/node/shell/state.mli b/src/node/shell/state.mli index 9aa5dbccf..e5084f6b9 100644 --- a/src/node/shell/state.mli +++ b/src/node/shell/state.mli @@ -132,7 +132,7 @@ end (** The local and distributed database of blocks. *) module Block : sig - type shell_header = Store.shell_block_header = { + type shell_header = Store.shell_block = { net_id: net_id ; (** The genesis of the chain this block belongs to. *) predecessor: Block_hash.t ; @@ -146,7 +146,7 @@ module Block : sig operations: Operation_hash.t list ; (** The raw part of the block header, as understood only by the protocol. *) } - type t = Store.block_header = { + type t = Store.block = { shell: shell_header ; proto: MBytes.t ; } diff --git a/src/node/shell/validator.ml b/src/node/shell/validator.ml index cc09e47c2..7ce9373cf 100644 --- a/src/node/shell/validator.ml +++ b/src/node/shell/validator.ml @@ -15,7 +15,7 @@ type worker = { get: State.net_id -> t tzresult Lwt.t ; get_exn: State.net_id -> t Lwt.t ; deactivate: t -> unit Lwt.t ; - notify_block: Block_hash.t -> Store.block_header -> unit Lwt.t ; + notify_block: Block_hash.t -> Store.block -> unit Lwt.t ; shutdown: unit -> unit Lwt.t ; } @@ -25,7 +25,7 @@ and t = { parent: t option ; mutable child: t option ; prevalidator: Prevalidator.t ; - notify_block: Block_hash.t -> Store.block_header -> unit Lwt.t ; + notify_block: Block_hash.t -> Store.block -> unit Lwt.t ; fetch_block: Block_hash.t -> State.Valid_block.t tzresult Lwt.t ; create_child: State.Valid_block.t -> unit tzresult Lwt.t ; test_validator: unit -> (t * State.Net.t) option ; @@ -126,7 +126,7 @@ let apply_block net (pred: State.Valid_block.t) hash (block: State.Block.t) = Protocol_hash.pp_short Proto.hash >>= fun () -> lwt_debug "validation of %a: parsing header..." Block_hash.pp_short hash >>= fun () -> - Lwt.return (Proto.parse_block_header block) >>=? fun parsed_header -> + Lwt.return (Proto.parse_block block) >>=? fun parsed_header -> lwt_debug "validation of %a: parsing operations..." Block_hash.pp_short hash >>= fun () -> map2_s @@ -148,7 +148,7 @@ module Validation_scheduler = struct let name = "validator" type state = State.Net.t * Block_hash_set.t ref type rdata = t - type data = Store.block_header Time.timed_data + type data = Store.block Time.timed_data let init_request (net, _) hash = State.Block.fetch (State.Net.state net) (State.Net.id net) hash @@ -344,7 +344,7 @@ let create_worker p2p state = v.shutdown () in - let notify_block hash (block : Store.block_header) = + let notify_block hash (block : Store.block) = match get_exn block.shell.net_id with | exception Not_found -> Lwt.return_unit | net -> diff --git a/src/node/shell/validator.mli b/src/node/shell/validator.mli index d7826dbe8..2a43bc734 100644 --- a/src/node/shell/validator.mli +++ b/src/node/shell/validator.mli @@ -12,7 +12,7 @@ type worker val create_worker: P2p.net -> State.t -> worker val shutdown: worker -> unit Lwt.t -val notify_block: worker -> Block_hash.t -> Store.block_header -> unit Lwt.t +val notify_block: worker -> Block_hash.t -> Store.block -> unit Lwt.t type t diff --git a/src/node/updater/protocol.mli b/src/node/updater/protocol.mli index a4bfc8398..88867d1f8 100644 --- a/src/node/updater/protocol.mli +++ b/src/node/updater/protocol.mli @@ -26,7 +26,7 @@ type raw_operation = Store.operation = { } (** The version agnostic toplevel structure of blocks. *) -type shell_block_header = Store.shell_block_header = +type shell_block = Store.shell_block = { net_id: net_id ; (** The genesis of the chain this block belongs to. *) predecessor: Block_hash.t ; @@ -41,8 +41,8 @@ type shell_block_header = Store.shell_block_header = (** The sequence of operations. *) } -type raw_block_header = Store.block_header = { - shell: shell_block_header ; +type raw_block = Store.block = { + shell: shell_block ; proto: MBytes.t ; } @@ -76,10 +76,10 @@ module type PROTOCOL = sig val max_operation_data_length : int (** The version specific part of blocks. *) - type block_header + type block (** The maximum size of block headers in bytes *) - val max_block_header_length : int + val max_block_length : int (** The maximum *) val max_number_of_operations : int @@ -87,21 +87,21 @@ module type PROTOCOL = sig (** The parsing / preliminary validation function for blocks. Its role is to check that the raw header is well formed, and to produce a pre-decomposed value of the high level, protocol defined - {!block_header} type. It does not have access to the storage + {!block} type. It does not have access to the storage context. It may store the hash and raw bytes for later signature verification by {!apply} or {!preapply}. *) - val parse_block_header : raw_block_header -> block_header tzresult + val parse_block : raw_block -> block tzresult (** The parsing / preliminary validation function for - operations. Similar to {!parse_block_header}. *) + operations. Similar to {!parse_block}. *) val parse_operation : Operation_hash.t -> raw_operation -> operation tzresult (** The main protocol function that validates blocks. It receives the block header and the list of associated operations, as - pre-decomposed by {!parse_block_header} and {!parse_operation}. *) + pre-decomposed by {!parse_block} and {!parse_operation}. *) val apply : - Context.t -> block_header -> operation list -> + Context.t -> block -> operation list -> Context.t tzresult Lwt.t (** The auxiliary protocol entry point that validates pending diff --git a/src/node/updater/register.ml b/src/node/updater/register.ml index af075fd0e..9e1ee9242 100644 --- a/src/node/updater/register.ml +++ b/src/node/updater/register.ml @@ -34,7 +34,7 @@ let register proto = let module V = struct include Proto include Make(Proto) - let parse_block_header d = parse_block_header d |> wrap_error + let parse_block d = parse_block d |> wrap_error let parse_operation h b = parse_operation h b |> wrap_error let apply c h ops = apply c h ops >|= wrap_error let preapply c h t b ops = diff --git a/src/node/updater/updater.ml b/src/node/updater/updater.ml index 3f6ed4c2e..c7a7e2167 100644 --- a/src/node/updater/updater.ml +++ b/src/node/updater/updater.ml @@ -34,7 +34,7 @@ type raw_operation = Store.operation = { let raw_operation_encoding = Store.operation_encoding (** The version agnostic toplevel structure of blocks. *) -type shell_block_header = Store.shell_block_header = { +type shell_block = Store.shell_block = { net_id: net_id ; (** The genesis of the chain this block belongs to. *) predecessor: Block_hash.t ; @@ -48,13 +48,13 @@ type shell_block_header = Store.shell_block_header = { operations: Operation_hash.t list ; (** The sequence of operations. *) } -let shell_block_header_encoding = Store.shell_block_header_encoding +let shell_block_encoding = Store.shell_block_encoding -type raw_block_header = Store.block_header = { - shell: shell_block_header ; +type raw_block = Store.block = { + shell: shell_block ; proto: MBytes.t ; } -let raw_block_header_encoding = Store.block_header_encoding +let raw_block_encoding = Store.block_encoding type 'error preapply_result = 'error Protocol.preapply_result = { applied: Operation_hash.t list; diff --git a/src/node/updater/updater.mli b/src/node/updater/updater.mli index 0935018fe..05f90454e 100644 --- a/src/node/updater/updater.mli +++ b/src/node/updater/updater.mli @@ -23,7 +23,7 @@ type raw_operation = Store.operation = { val raw_operation_encoding: raw_operation Data_encoding.t (** The version agnostic toplevel structure of blocks. *) -type shell_block_header = Store.shell_block_header = { +type shell_block = Store.shell_block = { net_id: net_id ; (** The genesis of the chain this block belongs to. *) predecessor: Block_hash.t ; @@ -37,13 +37,13 @@ type shell_block_header = Store.shell_block_header = { operations: Operation_hash.t list ; (** The sequence of operations. *) } -val shell_block_header_encoding: shell_block_header Data_encoding.t +val shell_block_encoding: shell_block Data_encoding.t -type raw_block_header = Store.block_header = { - shell: shell_block_header ; +type raw_block = Store.block = { + shell: shell_block ; proto: MBytes.t ; } -val raw_block_header_encoding: raw_block_header Data_encoding.t +val raw_block_encoding: raw_block Data_encoding.t type 'error preapply_result = 'error Protocol.preapply_result = { applied: Operation_hash.t list; diff --git a/src/proto/bootstrap/apply.ml b/src/proto/bootstrap/apply.ml index 150e020f4..1248cd8f4 100644 --- a/src/proto/bootstrap/apply.ml +++ b/src/proto/bootstrap/apply.ml @@ -192,31 +192,31 @@ let may_start_new_cycle ctxt = ctxt last_cycle reward_date >>=? fun ctxt -> return ctxt -let apply_main ctxt accept_failing_script block_header operations = +let apply_main ctxt accept_failing_script block operations = (* read only checks *) - Mining.check_proof_of_work_stamp ctxt block_header >>=? fun () -> - Mining.check_fitness_gap ctxt block_header >>=? fun () -> - Mining.check_mining_rights ctxt block_header >>=? fun delegate_pkh -> - Mining.check_signature ctxt block_header delegate_pkh >>=? fun () -> + Mining.check_proof_of_work_stamp ctxt block >>=? fun () -> + Mining.check_fitness_gap ctxt block >>=? fun () -> + Mining.check_mining_rights ctxt block >>=? fun delegate_pkh -> + Mining.check_signature ctxt block delegate_pkh >>=? fun () -> (* automatic bonds payment *) - Mining.pay_mining_bond ctxt block_header delegate_pkh >>=? fun ctxt -> + Mining.pay_mining_bond ctxt block delegate_pkh >>=? fun ctxt -> (* set timestamp *) - Timestamp.set_current ctxt block_header.shell.timestamp >>=? fun ctxt -> + Timestamp.set_current ctxt block.shell.timestamp >>=? fun ctxt -> (* do effectful stuff *) Fitness.increase ctxt >>=? fun ctxt -> - let priority = snd block_header.proto.mining_slot in + let priority = snd block.proto.mining_slot in fold_left_s (fun ctxt operation -> apply_operation ctxt accept_failing_script (Some (Contract.default_contract delegate_pkh)) - block_header.shell.predecessor priority operation) + block.shell.predecessor priority operation) ctxt operations >>=? fun ctxt -> (* end of level (from this point nothing should fail) *) let reward = Mining.base_mining_reward ctxt - ~priority:(snd block_header.proto.mining_slot) in + ~priority:(snd block.proto.mining_slot) in Nonce.record_hash ctxt - delegate_pkh reward block_header.proto.seed_nonce_hash >>=? fun ctxt -> + delegate_pkh reward block.proto.seed_nonce_hash >>=? fun ctxt -> Reward.pay_due_rewards ctxt >>=? fun ctxt -> Level.increment_current ctxt >>=? fun ctxt -> (* end of cycle *) @@ -226,13 +226,13 @@ let apply_main ctxt accept_failing_script block_header operations = type error += Internal_error of string -let apply ctxt accept_failing_script block_header operations = +let apply ctxt accept_failing_script block operations = (init ctxt >>=? fun ctxt -> get_prevalidation ctxt >>= function | true -> fail (Internal_error "we should not call `apply` after `preapply`!") | false -> - apply_main ctxt accept_failing_script block_header operations >>=? fun ctxt -> + apply_main ctxt accept_failing_script block operations >>=? fun ctxt -> finalize ctxt) let empty_result = diff --git a/src/proto/bootstrap/block_repr.ml b/src/proto/bootstrap/block_repr.ml index 7982d8d78..5bb14a69b 100644 --- a/src/proto/bootstrap/block_repr.ml +++ b/src/proto/bootstrap/block_repr.ml @@ -13,7 +13,7 @@ open Tezos_hash (** Exported type *) type header = { - shell: Updater.shell_block_header ; + shell: Updater.shell_block ; proto: proto_header ; signature: Ed25519.signature ; } @@ -50,7 +50,7 @@ let signed_proto_header_encoding = let unsigned_header_encoding = let open Data_encoding in merge_objs - Updater.shell_block_header_encoding + Updater.shell_block_encoding proto_header_encoding (** Constants *) @@ -67,7 +67,7 @@ type error += let parse_header ({ shell = { net_id ; predecessor ; timestamp ; fitness ; operations } ; - proto } : Updater.raw_block_header) : header tzresult = + proto } : Updater.raw_block) : header tzresult = match Data_encoding.Binary.of_bytes signed_proto_header_encoding proto with | None -> Error [Cant_parse_proto_header] | Some (proto, signature) -> diff --git a/src/proto/bootstrap/block_repr.mli b/src/proto/bootstrap/block_repr.mli index 02509613e..b342365a6 100644 --- a/src/proto/bootstrap/block_repr.mli +++ b/src/proto/bootstrap/block_repr.mli @@ -11,7 +11,7 @@ open Tezos_hash (** Exported type *) type header = { - shell: Updater.shell_block_header ; + shell: Updater.shell_block ; proto: proto_header ; signature: Ed25519.signature ; } @@ -30,11 +30,11 @@ val mining_slot_encoding: mining_slot Data_encoding.encoding val max_header_length: int (** Parse the protocol-specific part of a block header. *) -val parse_header: Updater.raw_block_header -> header tzresult +val parse_header: Updater.raw_block -> header tzresult val unsigned_header_encoding: - (Updater.shell_block_header * proto_header) Data_encoding.encoding + (Updater.shell_block * proto_header) Data_encoding.encoding val forge_header: - Updater.shell_block_header -> proto_header -> MBytes.t + Updater.shell_block -> proto_header -> MBytes.t diff --git a/src/proto/bootstrap/main.ml b/src/proto/bootstrap/main.ml index b002a7ac6..6b07d6bdf 100644 --- a/src/proto/bootstrap/main.ml +++ b/src/proto/bootstrap/main.ml @@ -16,16 +16,16 @@ let parse_operation = Tezos_context.Operation.parse let max_operation_data_length = Tezos_context.Operation.max_operation_data_length -type block_header = +type block = Tezos_context.Block.header -let parse_block_header = +let parse_block = Tezos_context.Block.parse_header let max_number_of_operations = Tezos_context.Constants.max_number_of_operations -let max_block_header_length = +let max_block_length = Tezos_context.Block.max_header_length let rpc_services = Services_registration.rpc_services diff --git a/src/proto/bootstrap/mining.ml b/src/proto/bootstrap/mining.ml index c6d765237..5a4693bca 100644 --- a/src/proto/bootstrap/mining.ml +++ b/src/proto/bootstrap/mining.ml @@ -156,19 +156,19 @@ type error += | Invalid_signature | Invalid_stamp -let check_proof_of_work_stamp ctxt block_header = +let check_proof_of_work_stamp ctxt block = let proof_of_work_threshold = Constants.proof_of_work_threshold ctxt in - if check_header_hash block_header proof_of_work_threshold then + if check_header_hash block proof_of_work_threshold then return () else fail Invalid_stamp -let check_signature ctxt block_header id = +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 Ed25519.check_signature key signature unsigned_header in - if check_signature key block_header then + if check_signature key block then return () else fail Invalid_signature @@ -179,9 +179,9 @@ let max_fitness_gap ctxt = type error += Invalid_fitness_gap -let check_fitness_gap ctxt (block_header : Block.header) = +let check_fitness_gap ctxt (block : Block.header) = Fitness.raw_get ctxt >>=? fun current_fitness -> - Fitness.raw_read block_header.shell.fitness >>=? fun announced_fitness -> + Fitness.raw_read block.shell.fitness >>=? fun announced_fitness -> let gap = Int64.sub announced_fitness current_fitness in if Compare.Int64.(gap <= 0L || max_fitness_gap ctxt < gap) then fail Invalid_fitness_gap diff --git a/src/proto/bootstrap/services.ml b/src/proto/bootstrap/services.ml index fc43a82f7..721d099c9 100644 --- a/src/proto/bootstrap/services.ml +++ b/src/proto/bootstrap/services.ml @@ -522,7 +522,7 @@ module Helpers = struct describe ~title: "new contracts" (list Contract.encoding)))) RPC.Path.(custom_root / "helpers" / "forge" / "operations" ) - let block_header custom_root = + let block custom_root = RPC.service ~description: "Forge a block header" ~input: @@ -538,7 +538,7 @@ module Helpers = struct (req "proof_of_work_nonce" (Fixed.bytes Tezos_context.Constants.proof_of_work_nonce_size))) ~output: (wrap_tzerror bytes) - RPC.Path.(custom_root / "helpers" / "forge" / "block_header") + RPC.Path.(custom_root / "helpers" / "forge" / "block") end diff --git a/src/proto/bootstrap/services_registration.ml b/src/proto/bootstrap/services_registration.ml index cba81697e..edbfeea33 100644 --- a/src/proto/bootstrap/services_registration.ml +++ b/src/proto/bootstrap/services_registration.ml @@ -389,7 +389,7 @@ let forge_operations ctxt (shell, proto) = let () = register1 Services.Helpers.Forge.operations forge_operations -let forge_block_header _ctxt +let forge_block _ctxt (net_id, predecessor, timestamp, fitness, operations, raw_level, priority, seed_nonce_hash, proof_of_work_nonce) : MBytes.t tzresult Lwt.t = let priority = Int32.of_int priority in @@ -398,7 +398,7 @@ let forge_block_header _ctxt { net_id ; predecessor ; timestamp ; fitness ; operations } { mining_slot ; seed_nonce_hash ; proof_of_work_nonce }) -let () = register1 Services.Helpers.Forge.block_header forge_block_header +let () = register1 Services.Helpers.Forge.block forge_block (*-- Helpers.Parse -----------------------------------------------------------*) diff --git a/src/proto/bootstrap/tezos_context.mli b/src/proto/bootstrap/tezos_context.mli index ad0eb8fe9..587b712b1 100644 --- a/src/proto/bootstrap/tezos_context.mli +++ b/src/proto/bootstrap/tezos_context.mli @@ -525,7 +525,7 @@ end module Block : sig type header = { - shell: Updater.shell_block_header ; + shell: Updater.shell_block ; proto: proto_header ; signature: Ed25519.signature ; } @@ -542,13 +542,13 @@ module Block : sig val max_header_length: int - val parse_header: Updater.raw_block_header -> header tzresult + val parse_header: Updater.raw_block -> header tzresult val unsigned_header_encoding: - (Updater.shell_block_header * proto_header) Data_encoding.encoding + (Updater.shell_block * proto_header) Data_encoding.encoding val forge_header: - Updater.shell_block_header -> proto_header -> MBytes.t + Updater.shell_block -> proto_header -> MBytes.t end diff --git a/src/proto/demo/main.ml b/src/proto/demo/main.ml index 81e996ac8..55ea1293e 100644 --- a/src/proto/demo/main.ml +++ b/src/proto/demo/main.ml @@ -10,12 +10,12 @@ type operation = Operation_hash.t let max_operation_data_length = 42 -type block_header = unit +type block = unit -let max_block_header_length = 42 +let max_block_length = 42 let max_number_of_operations = 42 -let parse_block_header _ = Ok () +let parse_block _ = Ok () let parse_operation h _ = Ok h let fitness_key = ["v1";"store";"fitness"] diff --git a/src/proto/environment/updater.mli b/src/proto/environment/updater.mli index 42c435d16..96df86124 100644 --- a/src/proto/environment/updater.mli +++ b/src/proto/environment/updater.mli @@ -17,7 +17,7 @@ type raw_operation = { (** The version agnostic toplevel structure of blocks. *) -type shell_block_header = { +type shell_block = { net_id: net_id ; (** The genesis of the chain this block belongs to. *) predecessor: Block_hash.t ; @@ -31,10 +31,10 @@ type shell_block_header = { operations: Operation_hash.t list ; (** The sequence of operations. *) } -val shell_block_header_encoding: shell_block_header Data_encoding.t +val shell_block_encoding: shell_block Data_encoding.t -type raw_block_header = { - shell: shell_block_header ; +type raw_block = { + shell: shell_block ; proto: MBytes.t ; } @@ -68,10 +68,10 @@ module type PROTOCOL = sig val max_operation_data_length : int (** The version specific part of blocks. *) - type block_header + type block (** The maximum size of block headers in bytes *) - val max_block_header_length : int + val max_block_length : int (** The maximum *) val max_number_of_operations : int @@ -79,21 +79,21 @@ module type PROTOCOL = sig (** The parsing / preliminary validation function for blocks. Its role is to check that the raw header is well formed, and to produce a pre-decomposed value of the high level, protocol defined - {!block_header} type. It does not have access to the storage + {!block} type. It does not have access to the storage context. It may store the hash and raw bytes for later signature verification by {!apply} or {!preapply}. *) - val parse_block_header : raw_block_header -> block_header tzresult + val parse_block : raw_block -> block tzresult (** The parsing / preliminary validation function for - operations. Similar to {!parse_block_header}. *) + operations. Similar to {!parse_block}. *) val parse_operation : Operation_hash.t -> raw_operation -> operation tzresult (** The main protocol function that validates blocks. It receives the block header and the list of associated operations, as - pre-decomposed by {!parse_block_header} and {!parse_operation}. *) + pre-decomposed by {!parse_block} and {!parse_operation}. *) val apply : - Context.t -> block_header -> operation list -> Context.t tzresult Lwt.t + Context.t -> block -> operation list -> Context.t tzresult Lwt.t (** The auxiliary protocol entry point that validates pending operations out of blocks. This function tries to apply the all diff --git a/test/Makefile b/test/Makefile index 3521c7841..e2dfecc9a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,7 +10,9 @@ OCAMLFLAGS = \ $(patsubst %, -package %, $(PACKAGES)) \ ${EXTRA_OCAMLFLAGS} -SOURCE_DIRECTORIES := $(addprefix ../src/, \ +SOURCE_DIRECTORIES := \ + lib \ +$(addprefix ../src/, \ utils \ compiler \ node/db \ diff --git a/test/lib/assert.mli b/test/lib/assert.mli index f62070db4..b5010dfd4 100644 --- a/test/lib/assert.mli +++ b/test/lib/assert.mli @@ -32,8 +32,8 @@ val equal_operation : val equal_block : ?msg:string -> - (Hash.Block_hash.t * Store.block_header) option -> - (Hash.Block_hash.t * Store.block_header) option -> + (Hash.Block_hash.t * Store.block) option -> + (Hash.Block_hash.t * Store.block) option -> unit val equal_result : diff --git a/test/test_context.ml b/test/test_context.ml index 0a6062921..c3f7efd5c 100644 --- a/test/test_context.ml +++ b/test/test_context.ml @@ -39,7 +39,7 @@ let block2 = Block_hash.of_hex "2222222222222222222222222222222222222222222222222222222222222222" -let faked_block : Store.block_header = { +let faked_block : Store.block = { shell = { net_id = Net genesis_block ; predecessor = genesis_block ; diff --git a/test/test_state.ml b/test/test_state.ml index a68b91e60..f27c0806d 100644 --- a/test/test_state.ml +++ b/test/test_state.ml @@ -59,7 +59,7 @@ let operation op = op, Store.Operation.to_bytes op -let block state ?(operations = []) pred_hash pred name : Store.block_header = +let block state ?(operations = []) pred_hash pred name : Store.block = let fitness = incr_fitness pred.Store.shell.fitness in let timestamp = incr_timestamp pred.Store.shell.timestamp in { shell = { @@ -121,8 +121,8 @@ let build_valid_chain state net tbl vtbl otbl pred names = State.Block.store state (Store.Block.to_bytes block) >>=? fun block' -> Assert.equal_block ~msg:__LOC__ (Some (hash, block)) block' ; Hashtbl.add tbl name (hash, block) ; - Lwt.return (Proto.parse_block_header block) >>=? fun block_header -> - Proto.apply pred.context block_header [] >>=? fun ctxt -> + Lwt.return (Proto.parse_block block) >>=? fun block -> + Proto.apply pred.context block [] >>=? fun ctxt -> State.Valid_block.store state hash ctxt >>=? fun vblock -> Hashtbl.add vtbl name vblock ; return vblock @@ -163,7 +163,7 @@ let build_example_tree state net = Lwt.return (tbl, vtbl, otbl) type state = { - block: (string, Block_hash.t * Store.block_header) Hashtbl.t ; + block: (string, Block_hash.t * Store.block) Hashtbl.t ; operation: (string, Operation_hash.t * Store.operation tzresult) Hashtbl.t ; vblock: (string, State.Valid_block.t) Hashtbl.t ; state: State.t ;