From 495e887538214a330de422c779c78e4ffb423445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Mon, 10 Apr 2017 17:06:11 +0200 Subject: [PATCH] RPC: minor improvements in naming consistency --- src/client/client_node_rpcs.ml | 26 +++--- src/client/client_node_rpcs.mli | 20 ++-- .../alpha/baker/client_mining_blocks.ml | 13 +-- .../alpha/baker/client_mining_blocks.mli | 6 +- .../alpha/baker/client_mining_forge.ml | 16 ++-- .../embedded/alpha/client_proto_rpcs.ml | 4 +- .../embedded/alpha/client_proto_rpcs.mli | 2 +- src/client/embedded/demo/client_proto_main.ml | 2 +- .../embedded/genesis/client_proto_main.ml | 3 +- src/node/db/store.ml | 16 ++-- src/node/db/store.mli | 2 +- src/node/shell/distributed_db.ml | 4 +- src/node/shell/node.ml | 39 ++++---- src/node/shell/node_rpc.ml | 19 ++-- src/node/shell/node_rpc_services.ml | 91 ++++++++----------- src/node/shell/node_rpc_services.mli | 17 ++-- src/node/shell/state.ml | 6 +- src/node/shell/state.mli | 2 +- src/node/shell/validator.ml | 2 +- src/node/updater/protocol.mli | 2 +- src/node/updater/updater.ml | 2 +- src/node/updater/updater.mli | 2 +- src/proto/alpha/block_repr.ml | 4 +- src/proto/alpha/services_registration.ml | 4 +- src/proto/environment/updater.mli | 4 +- src/proto/genesis/services.ml | 4 +- test/proto_alpha/proto_alpha_helpers.ml | 11 ++- test/shell/test_state.ml | 8 +- test/shell/test_store.ml | 4 +- 29 files changed, 166 insertions(+), 169 deletions(-) diff --git a/src/client/client_node_rpcs.ml b/src/client/client_node_rpcs.ml index 56398606f..d7c6d67d3 100644 --- a/src/client/client_node_rpcs.ml +++ b/src/client/client_node_rpcs.ml @@ -15,9 +15,9 @@ module Services = Node_rpc_services let errors cctxt = call_service0 cctxt Services.Error.service () -let forge_block cctxt ?net ?level ?predecessor ?timestamp fitness ops header = +let forge_block cctxt ?net_id ?level ?predecessor ?timestamp fitness ops header = call_service0 cctxt Services.forge_block - (net, level, predecessor, timestamp, fitness, ops, header) + (net_id, level, predecessor, timestamp, fitness, ops, header) let validate_block cctxt net block = call_err_service0 cctxt Services.validate_block (net, block) @@ -53,16 +53,16 @@ module Blocks = struct type block_info = Services.Blocks.block_info = { hash: Block_hash.t ; + net_id: Net_id.t ; level: Int32.t ; predecessor: Block_hash.t ; - fitness: MBytes.t list ; timestamp: Time.t ; - protocol: Protocol_hash.t option ; operations_hash: Operation_list_list_hash.t ; + fitness: MBytes.t list ; + data: MBytes.t ; operations: Operation_hash.t list list option ; - data: MBytes.t option ; - net: Net_id.t ; - test_protocol: Protocol_hash.t option ; + protocol: Protocol_hash.t ; + test_protocol: Protocol_hash.t ; test_network: (Net_id.t * Time.t) option ; } type preapply_param = Services.Blocks.preapply_param = { @@ -104,19 +104,19 @@ module Blocks = struct { operations ; sort ; timestamp } let pending_operations cctxt block = call_service1 cctxt Services.Blocks.pending_operations block () - let info cctxt ?(operations = true) ?(data = true) h = - call_service1 cctxt Services.Blocks.info h (operations, data) + let info cctxt ?(include_ops = true) h = + call_service1 cctxt Services.Blocks.info h include_ops let complete cctxt block prefix = call_service2 cctxt Services.Blocks.complete block prefix () - let list cctxt ?(operations = false) ?(data = false) + let list cctxt ?(include_ops = false) ?length ?heads ?delay ?min_date ?min_heads () = call_service0 cctxt Services.Blocks.list - { operations ; data ; length ; heads ; monitor = Some false ; delay ; + { include_ops ; length ; heads ; monitor = Some false ; delay ; min_date ; min_heads } - let monitor cctxt ?(operations = false) ?(data = false) + let monitor cctxt ?(include_ops = false) ?length ?heads ?delay ?min_date ?min_heads () = call_streamed_service0 cctxt Services.Blocks.list - { operations ; data ; length ; heads ; monitor = Some true ; delay ; + { include_ops ; length ; heads ; monitor = Some true ; delay ; min_date ; min_heads } end diff --git a/src/client/client_node_rpcs.mli b/src/client/client_node_rpcs.mli index 709ee3c80..82e9b17cc 100644 --- a/src/client/client_node_rpcs.mli +++ b/src/client/client_node_rpcs.mli @@ -14,7 +14,7 @@ val errors: val forge_block: config -> - ?net:Net_id.t -> + ?net_id:Net_id.t -> ?level:Int32.t -> ?predecessor:Block_hash.t -> ?timestamp:Time.t -> @@ -94,7 +94,7 @@ module Blocks : sig block -> Protocol_hash.t tzresult Lwt.t val test_protocol: config -> - block -> Protocol_hash.t option tzresult Lwt.t + block -> Protocol_hash.t tzresult Lwt.t val test_network: config -> block -> (Net_id.t * Time.t) option tzresult Lwt.t @@ -106,32 +106,32 @@ module Blocks : sig type block_info = { hash: Block_hash.t ; + net_id: Net_id.t ; level: Int32.t ; predecessor: Block_hash.t ; - fitness: MBytes.t list ; timestamp: Time.t ; - protocol: Protocol_hash.t option ; operations_hash: Operation_list_list_hash.t ; + fitness: MBytes.t list ; + data: MBytes.t ; operations: Operation_hash.t list list option ; - data: MBytes.t option ; - net: Net_id.t ; - test_protocol: Protocol_hash.t option ; + protocol: Protocol_hash.t ; + test_protocol: Protocol_hash.t ; test_network: (Net_id.t * Time.t) option ; } val info: config -> - ?operations:bool -> ?data:bool -> block -> block_info tzresult Lwt.t + ?include_ops:bool -> block -> block_info tzresult Lwt.t val list: config -> - ?operations:bool -> ?data:bool -> ?length:int -> ?heads:Block_hash.t list -> + ?include_ops:bool -> ?length:int -> ?heads:Block_hash.t list -> ?delay:int -> ?min_date:Time.t -> ?min_heads:int -> unit -> block_info list list tzresult Lwt.t val monitor: config -> - ?operations:bool -> ?data:bool -> ?length:int -> ?heads:Block_hash.t list -> + ?include_ops:bool -> ?length:int -> ?heads:Block_hash.t list -> ?delay:int -> ?min_date:Time.t -> ?min_heads:int -> unit -> block_info list list tzresult Lwt_stream.t tzresult Lwt.t diff --git a/src/client/embedded/alpha/baker/client_mining_blocks.ml b/src/client/embedded/alpha/baker/client_mining_blocks.ml index 48c84f48d..e524b4284 100644 --- a/src/client/embedded/alpha/baker/client_mining_blocks.ml +++ b/src/client/embedded/alpha/baker/client_mining_blocks.ml @@ -12,7 +12,7 @@ type block_info = { predecessor: Block_hash.t ; fitness: MBytes.t list ; timestamp: Time.t ; - protocol: Protocol_hash.t option ; + protocol: Protocol_hash.t ; level: Level.t ; } @@ -21,7 +21,8 @@ let convert_block_info cctxt : Client_node_rpcs.Blocks.block_info ) = Client_proto_rpcs.Context.level cctxt (`Hash hash) >>= function | Ok level -> - Lwt.return (Some { hash ; predecessor ; fitness ; timestamp ; protocol ; level }) + Lwt.return + (Some { hash ; predecessor ; fitness ; timestamp ; protocol ; level }) | Error _ -> (* TODO log error *) Lwt.return_none @@ -32,8 +33,8 @@ let convert_block_info_err cctxt Client_proto_rpcs.Context.level cctxt (`Hash hash) >>=? fun level -> return { hash ; predecessor ; fitness ; timestamp ; protocol ; level } -let info cctxt ?operations block = - Client_node_rpcs.Blocks.info cctxt ?operations block >>=? fun block -> +let info cctxt ?include_ops block = + Client_node_rpcs.Blocks.info cctxt ?include_ops block >>=? fun block -> convert_block_info_err cctxt block let compare (bi1 : block_info) (bi2 : block_info) = @@ -54,10 +55,10 @@ let sort_blocks cctxt ?(compare = compare) blocks = List.sort compare blocks let monitor cctxt - ?operations ?length ?heads ?delay + ?include_ops ?length ?heads ?delay ?min_date ?min_heads ?compare () = Client_node_rpcs.Blocks.monitor cctxt - ?operations ?length ?heads ?delay ?min_date ?min_heads + ?include_ops ?length ?heads ?delay ?min_date ?min_heads () >>=? fun block_stream -> let convert blocks = Lwt.return blocks >>=? fun blocks -> diff --git a/src/client/embedded/alpha/baker/client_mining_blocks.mli b/src/client/embedded/alpha/baker/client_mining_blocks.mli index 1cda9483f..cb1567f2f 100644 --- a/src/client/embedded/alpha/baker/client_mining_blocks.mli +++ b/src/client/embedded/alpha/baker/client_mining_blocks.mli @@ -12,20 +12,20 @@ type block_info = { predecessor: Block_hash.t ; fitness: MBytes.t list ; timestamp: Time.t ; - protocol: Protocol_hash.t option ; + protocol: Protocol_hash.t ; level: Level.t ; } val info: Client_rpcs.config -> - ?operations:bool -> Client_node_rpcs.Blocks.block -> block_info tzresult Lwt.t + ?include_ops:bool -> Client_node_rpcs.Blocks.block -> block_info tzresult Lwt.t val compare: block_info -> block_info -> int val monitor: Client_rpcs.config -> - ?operations:bool -> ?length:int -> ?heads:Block_hash.t list -> + ?include_ops:bool -> ?length:int -> ?heads:Block_hash.t list -> ?delay:int -> ?min_date:Time.t -> ?min_heads:int -> ?compare:(block_info -> block_info -> int) -> unit -> block_info list tzresult Lwt_stream.t tzresult Lwt.t diff --git a/src/client/embedded/alpha/baker/client_mining_forge.ml b/src/client/embedded/alpha/baker/client_mining_forge.ml index a85e683de..30427c09b 100644 --- a/src/client/embedded/alpha/baker/client_mining_forge.ml +++ b/src/client/embedded/alpha/baker/client_mining_forge.ml @@ -42,26 +42,26 @@ let rec compute_stamp let inject_block cctxt block ?force ~priority ~timestamp ~fitness ~seed_nonce - ~src_sk operation_list = + ~src_sk operations = let block = match block with `Prevalidation -> `Head 0 | block -> block in Client_node_rpcs.Blocks.info cctxt block >>=? fun bi -> let seed_nonce_hash = Nonce.hash seed_nonce in Client_proto_rpcs.Context.next_level cctxt block >>=? fun level -> - let operations = + let operations_hash = Operation_list_list_hash.compute - (List.map Operation_list_hash.compute operation_list) in + (List.map Operation_list_hash.compute operations) in let shell = - { Store.Block_header.net_id = bi.net ; level = bi.level ; - predecessor = bi.hash ; timestamp ; fitness ; operations } in + { Store.Block_header.net_id = bi.net_id ; level = bi.level ; + predecessor = bi.hash ; timestamp ; fitness ; operations_hash } in compute_stamp cctxt block src_sk shell priority seed_nonce_hash >>=? fun proof_of_work_nonce -> Client_proto_rpcs.Helpers.Forge.block cctxt block - ~net:bi.net + ~net:bi.net_id ~predecessor:bi.hash ~timestamp ~fitness - ~operations + ~operations_hash ~level:level.level ~priority:priority ~seed_nonce_hash @@ -69,7 +69,7 @@ let inject_block cctxt block () >>=? fun unsigned_header -> let signed_header = Ed25519.Signature.append src_sk unsigned_header in Client_node_rpcs.inject_block cctxt - ?force signed_header operation_list >>=? fun block_hash -> + ?force signed_header operations >>=? fun block_hash -> return block_hash let forge_block cctxt block diff --git a/src/client/embedded/alpha/client_proto_rpcs.ml b/src/client/embedded/alpha/client_proto_rpcs.ml index 2cdf0c08f..b7f49553a 100644 --- a/src/client/embedded/alpha/client_proto_rpcs.ml +++ b/src/client/embedded/alpha/client_proto_rpcs.ml @@ -245,10 +245,10 @@ module Helpers = struct operations cctxt block ~net [Faucet { id ; nonce }] end let block cctxt - block ~net ~predecessor ~timestamp ~fitness ~operations + block ~net ~predecessor ~timestamp ~fitness ~operations_hash ~level ~priority ~seed_nonce_hash ~proof_of_work_nonce () = call_error_service1 cctxt Services.Helpers.Forge.block block - (net, predecessor, timestamp, fitness, operations, + (net, predecessor, timestamp, fitness, operations_hash, level, priority, seed_nonce_hash, proof_of_work_nonce) end diff --git a/src/client/embedded/alpha/client_proto_rpcs.mli b/src/client/embedded/alpha/client_proto_rpcs.mli index a81badd80..64ab01a15 100644 --- a/src/client/embedded/alpha/client_proto_rpcs.mli +++ b/src/client/embedded/alpha/client_proto_rpcs.mli @@ -298,7 +298,7 @@ module Helpers : sig predecessor:Block_hash.t -> timestamp:Time.t -> fitness:Fitness.t -> - operations:Operation_list_list_hash.t -> + operations_hash:Operation_list_list_hash.t -> level:Raw_level.t -> priority:int -> seed_nonce_hash:Nonce_hash.t -> diff --git a/src/client/embedded/demo/client_proto_main.ml b/src/client/embedded/demo/client_proto_main.ml index 621eff46d..2dc1c5394 100644 --- a/src/client/embedded/demo/client_proto_main.ml +++ b/src/client/embedded/demo/client_proto_main.ml @@ -51,7 +51,7 @@ let mine cctxt = (cctxt.message "Cannot parse fitness: %a" Fitness.pp bi.fitness); exit 2 in Client_node_rpcs.forge_block cctxt.rpc_config - ~net:bi.net ~predecessor:bi.hash + ~net_id:bi.net_id ~predecessor:bi.hash fitness Operation_list_list_hash.empty (MBytes.create 0) >>=? fun bytes -> Client_node_rpcs.inject_block cctxt.rpc_config bytes [] >>=? fun hash -> cctxt.answer "Injected %a" Block_hash.pp_short hash >>= fun () -> diff --git a/src/client/embedded/genesis/client_proto_main.ml b/src/client/embedded/genesis/client_proto_main.ml index 5be95a50e..b9897eb87 100644 --- a/src/client/embedded/genesis/client_proto_main.ml +++ b/src/client/embedded/genesis/client_proto_main.ml @@ -33,7 +33,8 @@ let forge_block let mine rpc_config ?timestamp block command fitness seckey = Client_blocks.get_block_info rpc_config block >>=? fun bi -> - forge_block rpc_config ?timestamp block bi.net command fitness >>=? fun blk -> + forge_block + rpc_config ?timestamp block bi.net_id command fitness >>=? fun blk -> let signed_blk = Environment.Ed25519.Signature.append seckey blk in Client_node_rpcs.inject_block rpc_config signed_blk [[]] diff --git a/src/node/db/store.ml b/src/node/db/store.ml index 65c3b29cf..f0c410234 100644 --- a/src/node/db/store.ml +++ b/src/node/db/store.ml @@ -261,7 +261,7 @@ module Block_header = struct level: Int32.t ; predecessor: Block_hash.t ; timestamp: Time.t ; - operations: Operation_list_list_hash.t ; + operations_hash: Operation_list_list_hash.t ; fitness: MBytes.t list ; } @@ -269,17 +269,19 @@ module Block_header = struct let open Data_encoding in conv (fun { net_id ; level ; predecessor ; - timestamp ; operations ; fitness } -> - (net_id, level, predecessor, timestamp, operations, fitness)) - (fun (net_id, level, predecessor, timestamp, operations, fitness) -> + timestamp ; operations_hash ; fitness } -> + (net_id, level, predecessor, + timestamp, operations_hash, fitness)) + (fun (net_id, level, predecessor, + timestamp, operations_hash, fitness) -> { net_id ; level ; predecessor ; - timestamp ; operations ; fitness }) + timestamp ; operations_hash ; fitness }) (obj6 (req "net_id" Net_id.encoding) (req "level" int32) (req "predecessor" Block_hash.encoding) (req "timestamp" Time.encoding) - (req "operations" Operation_list_list_hash.encoding) + (req "operations_hash" Operation_list_list_hash.encoding) (req "fitness" Fitness.encoding)) module Encoding = struct @@ -311,7 +313,7 @@ module Block_header = struct Block_hash.compare b1.shell.predecessor b2.shell.predecessor >> fun () -> compare b1.proto b2.proto >> fun () -> Operation_list_list_hash.compare - b1.shell.operations b2.shell.operations >> fun () -> + b1.shell.operations_hash b2.shell.operations_hash >> fun () -> Time.compare b1.shell.timestamp b2.shell.timestamp >> fun () -> list compare b1.shell.fitness b2.shell.fitness diff --git a/src/node/db/store.mli b/src/node/db/store.mli index 395891caa..3e7552ab1 100644 --- a/src/node/db/store.mli +++ b/src/node/db/store.mli @@ -174,7 +174,7 @@ module Block_header : sig level: Int32.t ; predecessor: Block_hash.t ; timestamp: Time.t ; - operations: Operation_list_list_hash.t ; + operations_hash: Operation_list_list_hash.t ; fitness: MBytes.t list ; } val shell_header_encoding: shell_header Data_encoding.t diff --git a/src/node/shell/distributed_db.ml b/src/node/shell/distributed_db.ml index a4e8720ed..cdc3e6d31 100644 --- a/src/node/shell/distributed_db.ml +++ b/src/node/shell/distributed_db.ml @@ -348,7 +348,7 @@ module P2p_reader = struct | None -> Lwt.return_unit | Some bh -> if Operation_list_list_hash.compare - found_hash bh.shell.operations <> 0 then + found_hash bh.shell.operations_hash <> 0 then Lwt.return_unit else Raw_operation_list.Table.notify @@ -624,7 +624,7 @@ let inject_block t bytes operations = (List.map Operation_list_hash.compute operations) in fail_unless (Operation_list_list_hash.compare - computed_hash block.shell.operations = 0) + computed_hash block.shell.operations_hash = 0) (Exn (Failure "Incoherent operation list")) >>=? fun () -> Raw_block_header.Table.inject net_db.block_header_db.table hash block >>= function diff --git a/src/node/shell/node.ml b/src/node/shell/node.ml index 4cc5779fb..2620b193a 100644 --- a/src/node/shell/node.ml +++ b/src/node/shell/node.ml @@ -138,31 +138,31 @@ module RPC = struct type block = Node_rpc_services.Blocks.block type block_info = Node_rpc_services.Blocks.block_info = { hash: Block_hash.t ; + net_id: Net_id.t ; level: Int32.t ; predecessor: Block_hash.t ; - fitness: MBytes.t list ; timestamp: Time.t ; - protocol: Protocol_hash.t option ; operations_hash: Operation_list_list_hash.t ; + fitness: MBytes.t list ; + data: MBytes.t ; operations: Operation_hash.t list list option ; - data: MBytes.t option ; - net: Net_id.t ; - test_protocol: Protocol_hash.t option ; + protocol: Protocol_hash.t ; + test_protocol: Protocol_hash.t ; test_network: (Net_id.t * Time.t) option ; } - let convert (block: State.Valid_block.t) = { + let convert (block: State.Valid_block.t) = { hash = block.hash ; + net_id = block.net_id ; level = block.level ; predecessor = block.predecessor ; - fitness = block.fitness ; timestamp = block.timestamp ; - protocol = Some block.protocol_hash ; operations_hash = block.operations_hash ; + fitness = block.fitness ; + data = block.proto_header ; operations = Some block.operations ; - data = Some block.proto_header ; - net = block.net_id ; - test_protocol = Some block.test_protocol_hash ; + protocol = block.protocol_hash ; + test_protocol = block.test_protocol_hash ; test_network = block.test_network ; } @@ -268,6 +268,13 @@ module RPC = struct | Error _ -> Lwt.fail Not_found | Ok { context ; fitness } -> Context.get_protocol context >>= fun protocol -> + Context.get_test_protocol context >>= fun test_protocol -> + Context.get_test_network context >>= fun test_network -> + Context.get_test_network_expiration context >>= fun test_network_expiration -> + let test_network = + match test_network, test_network_expiration with + | Some n, Some t -> Some (n, t) + | _, None | None, _ -> None in let operations = let pv_result, _ = Prevalidator.operations pv in [ pv_result.applied ] in @@ -277,15 +284,15 @@ module RPC = struct predecessor = head.hash ; fitness ; timestamp = Prevalidator.timestamp pv ; - protocol = Some protocol ; + protocol ; operations_hash = Operation_list_list_hash.compute (List.map Operation_list_hash.compute operations) ; operations = Some operations ; - data = None ; - net = head.net_id ; - test_protocol = None ; - test_network = None ; + data = MBytes.of_string "" ; + net_id = head.net_id ; + test_protocol ; + test_network ; } let rpc_context block : Updater.rpc_context = diff --git a/src/node/shell/node_rpc.ml b/src/node/shell/node_rpc.ml index 7933d6dba..862107e46 100644 --- a/src/node/shell/node_rpc.ml +++ b/src/node/shell/node_rpc.ml @@ -12,9 +12,8 @@ open Logging.RPC module Services = Node_rpc_services -let filter_bi (operations, data) (bi: Services.Blocks.block_info) = +let filter_bi operations (bi: Services.Blocks.block_info) = let bi = if operations then bi else { bi with operations = None } in - let bi = if data then bi else { bi with data = None } in bi let register_bi_dir node dir = @@ -34,7 +33,7 @@ let register_bi_dir node dir = let dir = let implementation b () = Node.RPC.block_info node b >>= fun bi -> - RPC.Answer.return bi.net in + RPC.Answer.return bi.net_id in RPC.register1 dir Services.Blocks.net implementation in let dir = @@ -71,9 +70,7 @@ let register_bi_dir node dir = let dir = let implementation b () = Node.RPC.block_info node b >>= fun bi -> - match bi.protocol with - | None -> raise Not_found - | Some p -> RPC.Answer.return p in + RPC.Answer.return bi.protocol in RPC.register1 dir Services.Blocks.protocol implementation in let dir = @@ -220,11 +217,10 @@ let create_delayed_stream let list_blocks node - { Services.Blocks.operations ; data ; length ; heads ; monitor ; delay ; + { Services.Blocks.include_ops ; length ; heads ; monitor ; delay ; min_date; min_heads} = let len = match length with None -> 1 | Some x -> x in let monitor = match monitor with None -> false | Some x -> x in - let include_ops = (operations, data) in let time = match delay with | None -> None @@ -410,16 +406,17 @@ let build_rpc_directory node = let dir = RPC.register1 dir Services.Protocols.contents (get_protocols node) in let dir = - let implementation (net_id, level, pred, time, fitness, operations, header) = + let implementation + (net_id, level, pred, time, fitness, operations_hash, header) = Node.RPC.block_info node (`Head 0) >>= fun bi -> let timestamp = Utils.unopt ~default:(Time.now ()) time in - let net_id = Utils.unopt ~default:bi.net net_id in + let net_id = Utils.unopt ~default:bi.net_id net_id in let predecessor = Utils.unopt ~default:bi.hash pred in let level = Utils.unopt ~default:(Int32.succ bi.level) level in let res = Data_encoding.Binary.to_bytes Store.Block_header.encoding { shell = { net_id ; predecessor ; level ; - timestamp ; fitness ; operations } ; + timestamp ; fitness ; operations_hash } ; proto = header ; } in RPC.Answer.return res in diff --git a/src/node/shell/node_rpc_services.ml b/src/node/shell/node_rpc_services.ml index 806f6058f..30ea27ae1 100644 --- a/src/node/shell/node_rpc_services.ml +++ b/src/node/shell/node_rpc_services.ml @@ -57,48 +57,46 @@ module Blocks = struct type block_info = { hash: Block_hash.t ; + net_id: Net_id.t ; level: Int32.t ; predecessor: Block_hash.t ; - fitness: MBytes.t list ; timestamp: Time.t ; - protocol: Protocol_hash.t option ; operations_hash: Operation_list_list_hash.t ; + fitness: MBytes.t list ; + data: MBytes.t ; operations: Operation_hash.t list list option ; - data: MBytes.t option ; - net: Net_id.t ; - test_protocol: Protocol_hash.t option ; + protocol: Protocol_hash.t ; + test_protocol: Protocol_hash.t ; test_network: (Net_id.t * Time.t) option ; } let block_info_encoding = conv - (fun { hash ; level ; predecessor ; fitness ; timestamp ; protocol ; - operations_hash ; operations ; data ; net ; - test_protocol ; test_network } -> - ((hash, level, predecessor, fitness, timestamp, protocol), - (operations_hash, operations, data, - net, test_protocol, test_network))) - (fun ((hash, level, predecessor, fitness, timestamp, protocol), - (operations_hash, operations, data, - net, test_protocol, test_network)) -> - { hash ; level ; predecessor ; fitness ; timestamp ; protocol ; - operations_hash ; operations ; data ; net ; - test_protocol ; test_network }) - (merge_objs - (obj6 - (req "hash" Block_hash.encoding) - (req "level" int32) - (req "predecessor" Block_hash.encoding) - (req "fitness" Fitness.encoding) - (req "timestamp" Time.encoding) - (opt "protocol" Protocol_hash.encoding)) - (obj6 - (req "operations_hash" Operation_list_list_hash.encoding) - (opt "operations" (list (list Operation_hash.encoding))) - (opt "data" bytes) - (req "net" Net_id.encoding) - (opt "test_protocol" Protocol_hash.encoding) - (opt "test_network" (tup2 Net_id.encoding Time.encoding)))) + (fun { hash ; net_id ; level ; predecessor ; + fitness ; timestamp ; protocol ; operations_hash ; data ; + operations ; test_protocol ; test_network } -> + ({ Store.Block_header.shell = + { net_id ; level ; predecessor ; + timestamp ; operations_hash ; fitness } ; + proto = data }, + (hash, operations, protocol, test_protocol, test_network))) + (fun ({ Store.Block_header.shell = + { net_id ; level ; predecessor ; + timestamp ; operations_hash ; fitness } ; + proto = data }, + (hash, operations, protocol, test_protocol, test_network)) -> + { hash ; net_id ; level ; predecessor ; + fitness ; timestamp ; protocol ; operations_hash ; data ; + operations ; test_protocol ; test_network }) + (dynamic_size + (merge_objs + Store.Block_header.encoding + (obj5 + (req "hash" Block_hash.encoding) + (opt "operations" (list (list Operation_hash.encoding))) + (req "protocol" Protocol_hash.encoding) + (req "test_protocol" Protocol_hash.encoding) + (opt "test_network" (tup2 Net_id.encoding Time.encoding))))) let parse_block s = try @@ -181,10 +179,7 @@ module Blocks = struct let info = RPC.service ~description:"All the information about a block." - ~input: - (obj2 - (dft "operations" bool true) - (dft "data" bool true)) + ~input: (obj1 (dft "operations" bool true)) ~output: block_info_encoding block_path @@ -257,7 +252,7 @@ module Blocks = struct RPC.service ~description:"List the block test protocol." ~input: empty - ~output: (obj1 (opt "protocol" Protocol_hash.encoding)) + ~output: (obj1 (req "protocol" Protocol_hash.encoding)) RPC.Path.(block_path / "test_protocol") let test_network = @@ -329,8 +324,7 @@ module Blocks = struct RPC.Path.(block_path / "complete" /: prefix_arg ) type list_param = { - operations: bool ; - data: bool ; + include_ops: bool ; length: int option ; heads: Block_hash.t list option ; monitor: bool option ; @@ -340,25 +334,20 @@ module Blocks = struct } let list_param_encoding = conv - (fun { operations ; data ; length ; heads ; monitor ; + (fun { include_ops ; length ; heads ; monitor ; delay ; min_date ; min_heads } -> - (operations, data, length, heads, monitor, delay, min_date, min_heads)) - (fun (operations, data, length, heads, monitor, delay, min_date, min_heads) -> - { operations ; data ; length ; heads ; monitor ; + (include_ops, length, heads, monitor, delay, min_date, min_heads)) + (fun (include_ops, length, heads, monitor, + delay, min_date, min_heads) -> + { include_ops ; length ; heads ; monitor ; delay ; min_date ; min_heads }) - (obj8 - (dft "operations" + (obj7 + (dft "include_ops" (Data_encoding.describe ~description: "Whether the resulting block informations should include the \ list of operations' hashes. Default false." bool) false) - (dft "data" - (Data_encoding.describe - ~description: - "Whether the resulting block informations should include the \ - raw protocol dependent data. Default false." - bool) false) (opt "length" (Data_encoding.describe ~description: diff --git a/src/node/shell/node_rpc_services.mli b/src/node/shell/node_rpc_services.mli index 99861742d..4daa660f4 100644 --- a/src/node/shell/node_rpc_services.mli +++ b/src/node/shell/node_rpc_services.mli @@ -28,21 +28,21 @@ module Blocks : sig type block_info = { hash: Block_hash.t ; + net_id: Net_id.t ; level: Int32.t ; predecessor: Block_hash.t ; - fitness: MBytes.t list ; timestamp: Time.t ; - protocol: Protocol_hash.t option ; operations_hash: Operation_list_list_hash.t ; + fitness: MBytes.t list ; + data: MBytes.t ; operations: Operation_hash.t list list option ; - data: MBytes.t option ; - net: Net_id.t ; - test_protocol: Protocol_hash.t option ; + protocol: Protocol_hash.t ; + test_protocol: Protocol_hash.t ; test_network: (Net_id.t * Time.t) option ; } val info: - (unit, unit * block, bool * bool, block_info) RPC.service + (unit, unit * block, bool, block_info) RPC.service val net: (unit, unit * block, unit, Net_id.t) RPC.service val level: @@ -62,7 +62,7 @@ module Blocks : sig val protocol: (unit, unit * block, unit, Protocol_hash.t) RPC.service val test_protocol: - (unit, unit * block, unit, Protocol_hash.t option) RPC.service + (unit, unit * block, unit, Protocol_hash.t) RPC.service val test_network: (unit, unit * block, unit, (Net_id.t * Time.t) option) RPC.service val pending_operations: @@ -70,8 +70,7 @@ module Blocks : sig error Prevalidation.preapply_result * Hash.Operation_hash.Set.t) RPC.service type list_param = { - operations: bool ; - data: bool ; + include_ops: bool ; length: int option ; heads: Block_hash.t list option ; monitor: bool option ; diff --git a/src/node/shell/state.ml b/src/node/shell/state.ml index de6f3a199..ef6ec6196 100644 --- a/src/node/shell/state.ml +++ b/src/node/shell/state.ml @@ -149,7 +149,7 @@ let build_valid_block predecessor = header.shell.predecessor ; timestamp = header.shell.timestamp ; discovery_time ; - operations_hash = header.shell.operations ; + operations_hash = header.shell.operations_hash ; operations ; fitness = header.shell.fitness ; protocol_hash ; @@ -546,7 +546,7 @@ module Raw_block_header = struct predecessor = genesis.block ; timestamp = genesis.time ; fitness = [] ; - operations = Operation_list_list_hash.empty ; + operations_hash = Operation_list_list_hash.empty ; } in let header = { Store.Block_header.shell ; proto = MBytes.create 0 } in @@ -700,7 +700,7 @@ module Block_header = struct level: Int32.t ; predecessor: Block_hash.t ; timestamp: Time.t ; - operations: Operation_list_list_hash.t ; + operations_hash: Operation_list_list_hash.t ; fitness: MBytes.t list ; } diff --git a/src/node/shell/state.mli b/src/node/shell/state.mli index 88289eb71..2b7e18d96 100644 --- a/src/node/shell/state.mli +++ b/src/node/shell/state.mli @@ -147,7 +147,7 @@ module Block_header : sig level: Int32.t ; predecessor: Block_hash.t ; timestamp: Time.t ; - operations: Operation_list_list_hash.t ; + operations_hash: Operation_list_list_hash.t ; fitness: MBytes.t list ; } diff --git a/src/node/shell/validator.ml b/src/node/shell/validator.ml index e7870a843..95aed3d4e 100644 --- a/src/node/shell/validator.ml +++ b/src/node/shell/validator.ml @@ -173,7 +173,7 @@ let apply_block net db lwt_log_info "validation of %a: looking for dependencies..." Block_hash.pp_short hash >>= fun () -> Distributed_db.Operation_list.fetch - db (hash, 0) block.shell.operations >>= fun operation_hashes -> + db (hash, 0) block.shell.operations_hash >>= fun operation_hashes -> Lwt_list.map_p (fun op -> Distributed_db.Operation.fetch db op) operation_hashes >>= fun operations -> diff --git a/src/node/updater/protocol.mli b/src/node/updater/protocol.mli index 829bfced7..7ead89112 100644 --- a/src/node/updater/protocol.mli +++ b/src/node/updater/protocol.mli @@ -27,7 +27,7 @@ type shell_block = Store.Block_header.shell_header = level: Int32.t ; predecessor: Block_hash.t ; timestamp: Time.t ; - operations: Operation_list_list_hash.t ; + operations_hash: Operation_list_list_hash.t ; fitness: MBytes.t list ; } diff --git a/src/node/updater/updater.ml b/src/node/updater/updater.ml index e47a07f53..a042ef063 100644 --- a/src/node/updater/updater.ml +++ b/src/node/updater/updater.ml @@ -48,7 +48,7 @@ type shell_block = Store.Block_header.shell_header = { level: Int32.t ; predecessor: Block_hash.t ; timestamp: Time.t ; - operations: Operation_list_list_hash.t ; + operations_hash: Operation_list_list_hash.t ; fitness: MBytes.t list ; } let shell_block_encoding = Store.Block_header.shell_header_encoding diff --git a/src/node/updater/updater.mli b/src/node/updater/updater.mli index eab745b70..38b0b2728 100644 --- a/src/node/updater/updater.mli +++ b/src/node/updater/updater.mli @@ -23,7 +23,7 @@ type shell_block = Store.Block_header.shell_header = { level: Int32.t ; predecessor: Block_hash.t ; timestamp: Time.t ; - operations: Operation_list_list_hash.t ; + operations_hash: Operation_list_list_hash.t ; fitness: MBytes.t list ; } val shell_block_encoding: shell_block Data_encoding.t diff --git a/src/proto/alpha/block_repr.ml b/src/proto/alpha/block_repr.ml index 28f5708a1..22fda8587 100644 --- a/src/proto/alpha/block_repr.ml +++ b/src/proto/alpha/block_repr.ml @@ -63,14 +63,14 @@ type error += let parse_header ({ shell = { net_id ; level ; predecessor ; - timestamp ; fitness ; operations } ; + timestamp ; fitness ; operations_hash } ; 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) -> let shell = { Updater.net_id ; level ; predecessor ; - timestamp ; fitness ; operations } in + timestamp ; fitness ; operations_hash } in Ok { shell ; proto ; signature } let forge_header shell proto = diff --git a/src/proto/alpha/services_registration.ml b/src/proto/alpha/services_registration.ml index 3d35bb845..b4bb98ef4 100644 --- a/src/proto/alpha/services_registration.ml +++ b/src/proto/alpha/services_registration.ml @@ -434,12 +434,12 @@ let forge_operations _ctxt (shell, proto) = let () = register1 Services.Helpers.Forge.operations forge_operations let forge_block _ctxt - (net_id, predecessor, timestamp, fitness, operations, + (net_id, predecessor, timestamp, fitness, operations_hash, level, priority, seed_nonce_hash, proof_of_work_nonce) : MBytes.t tzresult Lwt.t = let level = Raw_level.to_int32 level in return (Block.forge_header { net_id ; level ; predecessor ; - timestamp ; fitness ; operations } + timestamp ; fitness ; operations_hash } { priority ; seed_nonce_hash ; proof_of_work_nonce }) let () = register1 Services.Helpers.Forge.block forge_block diff --git a/src/proto/environment/updater.mli b/src/proto/environment/updater.mli index 6eb799f0b..8808ca0b1 100644 --- a/src/proto/environment/updater.mli +++ b/src/proto/environment/updater.mli @@ -25,8 +25,8 @@ type shell_block = { (** The preceding block in the chain. *) timestamp: Time.t ; (** The date at which this block has been forged. *) - operations: Operation_list_list_hash.t ; - (** The sequence of operations. *) + operations_hash: Operation_list_list_hash.t ; + (** The hash lf the merkle tree of operations. *) fitness: MBytes.t list ; (** The announced score of the block. As a sequence of sequences of unsigned bytes. Ordered by length and then by contents diff --git a/src/proto/genesis/services.ml b/src/proto/genesis/services.ml index 9983df0a3..36ffd1a53 100644 --- a/src/proto/genesis/services.ml +++ b/src/proto/genesis/services.ml @@ -54,7 +54,7 @@ let int64_to_bytes i = MBytes.set_int64 b 0 i; b -let operations = +let operations_hash = Operation_list_list_hash.compute [Operation_list_hash.empty] let rpc_services : Updater.rpc_context RPC.directory = @@ -65,7 +65,7 @@ let rpc_services : Updater.rpc_context RPC.directory = (Forge.block RPC.Path.root) (fun _ctxt ((net_id, level, predecessor, timestamp, fitness), command) -> let shell = { Updater.net_id ; level ; predecessor ; - timestamp ; fitness ; operations } in + timestamp ; fitness ; operations_hash } in let bytes = Data.Command.forge shell command in RPC.Answer.return bytes) in dir diff --git a/test/proto_alpha/proto_alpha_helpers.ml b/test/proto_alpha/proto_alpha_helpers.ml index 17575784c..592c3fd45 100644 --- a/test/proto_alpha/proto_alpha_helpers.ml +++ b/test/proto_alpha/proto_alpha_helpers.ml @@ -393,21 +393,22 @@ module Mining = struct Client_node_rpcs.Blocks.info rpc_config block >>=? fun bi -> let seed_nonce_hash = Nonce.hash seed_nonce in Client_proto_rpcs.Context.next_level rpc_config block >>=? fun level -> - let operations = + let operations_hash = Operation_list_list_hash.compute [Operation_list_hash.compute operation_list] in let shell = - { Store.Block_header.net_id = bi.net ; predecessor = bi.hash ; - timestamp ; fitness ; operations ; level = Raw_level.to_int32 level.level } in + { Store.Block_header.net_id = bi.net_id ; predecessor = bi.hash ; + timestamp ; fitness ; operations_hash ; + level = Raw_level.to_int32 level.level } in mine_stamp block src_sk shell priority seed_nonce_hash >>=? fun proof_of_work_nonce -> Client_proto_rpcs.Helpers.Forge.block rpc_config block - ~net:bi.net + ~net:bi.net_id ~predecessor:bi.hash ~timestamp ~fitness - ~operations + ~operations_hash ~level:level.level ~priority ~seed_nonce_hash diff --git a/test/shell/test_state.ml b/test/shell/test_state.ml index 09e80c141..b26911f8c 100644 --- a/test/shell/test_state.ml +++ b/test/shell/test_state.ml @@ -62,7 +62,7 @@ let operation op = Data_encoding.Binary.to_bytes Store.Operation.encoding op let block _state ?(operations = []) pred_hash pred name : Store.Block_header.t = - let operations = + let operations_hash = Operation_list_list_hash.compute [Operation_list_hash.compute operations] in let fitness = incr_fitness pred.Store.Block_header.shell.fitness in @@ -71,7 +71,7 @@ let block _state ?(operations = []) pred_hash pred name : Store.Block_header.t = net_id = pred.shell.net_id ; level = Int32.succ pred.shell.level ; predecessor = pred_hash ; - timestamp ; operations; fitness } ; + timestamp ; operations_hash ; fitness } ; proto = MBytes.of_string name ; } @@ -134,7 +134,7 @@ let build_chain state tbl otbl pred names = let block _state ?(operations = []) (pred: State.Valid_block.t) name : State.Block_header.t = - let operations = + let operations_hash = Operation_list_list_hash.compute [Operation_list_hash.compute operations] in let fitness = incr_fitness pred.fitness in @@ -142,7 +142,7 @@ let block _state ?(operations = []) (pred: State.Valid_block.t) name { shell = { net_id = pred.net_id ; level = Int32.succ pred.level ; predecessor = pred.hash ; - timestamp ; operations; fitness } ; + timestamp ; operations_hash ; fitness } ; proto = MBytes.of_string name ; } diff --git a/test/shell/test_store.ml b/test/shell/test_store.ml index c18968669..a5574be0c 100644 --- a/test/shell/test_store.ml +++ b/test/shell/test_store.ml @@ -89,14 +89,14 @@ let test_operation s = (** Block store *) let lolblock ?(operations = []) header = - let operations = + let operations_hash = Operation_list_list_hash.compute [Operation_list_hash.compute operations] in { Store.Block_header.shell = { timestamp = Time.of_seconds (Random.int64 1500L) ; level = 0l ; (* dummy *) net_id ; - predecessor = genesis_block ; operations ; + predecessor = genesis_block ; operations_hash ; fitness = [MBytes.of_string @@ string_of_int @@ String.length header; MBytes.of_string @@ string_of_int @@ 12] } ; proto = MBytes.of_string header ;