diff --git a/src/node/shell/node.ml b/src/node/shell/node.ml index 0cde44a97..0ea2ba288 100644 --- a/src/node/shell/node.ml +++ b/src/node/shell/node.ml @@ -295,11 +295,24 @@ module RPC = struct test_network ; } - let rpc_context block : Updater.rpc_context = - { context = block.State.Valid_block.context ; - level = Int32.succ block.level ; - fitness = block.fitness ; - timestamp = block. timestamp } + let rpc_context (block : State.Valid_block.t) : Updater.rpc_context = + { block_hash = block.hash ; + block_header = { + shell = { + net_id = block.net_id ; + level = block.level ; + proto_level = block.proto_level ; + predecessor = block.predecessor ; + timestamp = block.timestamp ; + operations_hash = block.operations_hash ; + fitness = block.fitness ; + } ; + proto = block.proto_header ; + } ; + operation_hashes = (fun () -> Lazy.force block.operation_hashes) ; + operations = (fun () -> Lazy.force block.operations) ; + context = block.context ; + } let get_rpc_context node block = match block with @@ -319,16 +332,48 @@ module RPC = struct | Some block -> Some (rpc_context block) end | ( `Prevalidation | `Test_prevalidation ) as block -> - let validator, net = get_net node block in + let validator, net_db = get_net node block in let pv = Validator.prevalidator validator in + let net_state = Validator.net_state validator in + State.Valid_block.Current.head net_state >>= fun head -> Prevalidator.context pv >>= function | Error _ -> Lwt.fail Not_found | Ok { context ; fitness } -> - let timestamp = Prevalidator.timestamp pv in - State.Valid_block.Current.head - (Distributed_db.state net) >>= fun { level } -> - let level = Int32.succ level in - Lwt.return (Some { Updater.context ; fitness ; timestamp ; level }) + Context.get_protocol context >>= fun protocol -> + let proto_level = + if Protocol_hash.equal protocol head.protocol_hash then + head.proto_level + else + ((head.proto_level + 1) mod 256) in + let operation_hashes = + let pv_result, _ = Prevalidator.operations pv in + [ pv_result.applied ] in + let operations_hash = + Operation_list_list_hash.compute + (List.map Operation_list_hash.compute operation_hashes) in + Lwt.return (Some { + Updater.block_hash = prevalidation_hash ; + block_header = { + shell = { + net_id = head.net_id ; + level = Int32.succ head.level ; + proto_level ; + predecessor = head.hash ; + timestamp = Prevalidator.timestamp pv ; + operations_hash ; + fitness ; + } ; + proto = MBytes.create 0 ; + } ; + operation_hashes = (fun () -> Lwt.return operation_hashes) ; + operations = begin fun () -> + Lwt_list.map_p + (Lwt_list.map_p + (Distributed_db.Operation.read_exn net_db)) + operation_hashes + end ; + context ; + }) let operations node block = match block with diff --git a/src/node/updater/protocol.mli b/src/node/updater/protocol.mli index 0bd8e85fe..61a47d056 100644 --- a/src/node/updater/protocol.mli +++ b/src/node/updater/protocol.mli @@ -44,10 +44,11 @@ type validation_result = { } type rpc_context = { + block_hash: Block_hash.t ; + block_header: raw_block_header ; + operation_hashes: unit -> Operation_hash.t list list Lwt.t ; + operations: unit -> raw_operation list list Lwt.t ; context: Context.t ; - level: Int32.t ; - timestamp: Time.t ; - fitness: Fitness.fitness ; } module type PROTOCOL = sig diff --git a/src/node/updater/updater.ml b/src/node/updater/updater.ml index 768f3b922..72a922186 100644 --- a/src/node/updater/updater.ml +++ b/src/node/updater/updater.ml @@ -11,19 +11,6 @@ open Logging.Updater let (//) = Filename.concat -type validation_result = Protocol.validation_result = { - context: Context.t ; - fitness: Fitness.fitness ; - message: string option ; -} - -type rpc_context = Protocol.rpc_context = { - context: Context.t ; - level: Int32.t ; - timestamp: Time.t ; - fitness: Fitness.fitness ; -} - module type PROTOCOL = Protocol.PROTOCOL module type REGISTRED_PROTOCOL = sig val hash: Protocol_hash.t @@ -60,6 +47,20 @@ type raw_block_header = Store.Block_header.t = { } let raw_block_header_encoding = Store.Block_header.encoding +type validation_result = Protocol.validation_result = { + context: Context.t ; + fitness: Fitness.fitness ; + message: string option ; +} + +type rpc_context = Protocol.rpc_context = { + block_hash: Block_hash.t ; + block_header: Protocol.raw_block_header ; + operation_hashes: unit -> Operation_hash.t list list Lwt.t ; + operations: unit -> raw_operation list list Lwt.t ; + context: Context.t ; +} + (** Version table *) module VersionTable = Protocol_hash.Table diff --git a/src/node/updater/updater.mli b/src/node/updater/updater.mli index 52ed2182c..64e9e04da 100644 --- a/src/node/updater/updater.mli +++ b/src/node/updater/updater.mli @@ -42,10 +42,11 @@ type validation_result = Protocol.validation_result = { } type rpc_context = Protocol.rpc_context = { + block_hash: Block_hash.t ; + block_header: raw_block_header ; + operation_hashes: unit -> Operation_hash.t list list Lwt.t ; + operations: unit -> raw_operation list list Lwt.t ; context: Context.t ; - level: Int32.t ; - timestamp: Time.t ; - fitness: Fitness.fitness ; } module type PROTOCOL = Protocol.PROTOCOL diff --git a/src/proto/alpha/services_registration.ml b/src/proto/alpha/services_registration.ml index 716aeecba..7c3e3256e 100644 --- a/src/proto/alpha/services_registration.ml +++ b/src/proto/alpha/services_registration.ml @@ -9,8 +9,11 @@ open Tezos_context -let rpc_init { Updater.context ; level ; timestamp ; fitness } = - Tezos_context.init ~level ~timestamp ~fitness context +let rpc_init rpc_context = + let level = Int32.succ rpc_context.Updater.block_header.shell.level in + let timestamp = rpc_context.block_header.shell.timestamp in + let fitness = rpc_context.block_header.shell.fitness in + Tezos_context.init ~level ~timestamp ~fitness rpc_context.context let rpc_services = ref (RPC.empty : Updater.rpc_context RPC.directory) let register0 s f = diff --git a/src/proto/environment/updater.mli b/src/proto/environment/updater.mli index 6830a42fc..878431931 100644 --- a/src/proto/environment/updater.mli +++ b/src/proto/environment/updater.mli @@ -51,8 +51,8 @@ type validation_result = { type rpc_context = { block_hash: Block_hash.t ; block_header: raw_block_header ; - operations_list: unit -> Operation_hash.t list list ; - operations: unit -> MBytes.t list list ; + operation_hashes: unit -> Operation_hash.t list list Lwt.t ; + operations: unit -> raw_operation list list Lwt.t ; context: Context.t ; }