Shell/Proto: export more information to the RPC handler

This commit is contained in:
Grégoire Henry 2017-04-14 00:07:01 +02:00
parent fb04fc1c17
commit 8a20ec8b0f
6 changed files with 85 additions and 34 deletions

View File

@ -295,11 +295,24 @@ module RPC = struct
test_network ; test_network ;
} }
let rpc_context block : Updater.rpc_context = let rpc_context (block : State.Valid_block.t) : Updater.rpc_context =
{ context = block.State.Valid_block.context ; { block_hash = block.hash ;
level = Int32.succ block.level ; 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 ; fitness = block.fitness ;
timestamp = block. timestamp } } ;
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 = let get_rpc_context node block =
match block with match block with
@ -319,16 +332,48 @@ module RPC = struct
| Some block -> Some (rpc_context block) | Some block -> Some (rpc_context block)
end end
| ( `Prevalidation | `Test_prevalidation ) as block -> | ( `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 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 Prevalidator.context pv >>= function
| Error _ -> Lwt.fail Not_found | Error _ -> Lwt.fail Not_found
| Ok { context ; fitness } -> | Ok { context ; fitness } ->
let timestamp = Prevalidator.timestamp pv in Context.get_protocol context >>= fun protocol ->
State.Valid_block.Current.head let proto_level =
(Distributed_db.state net) >>= fun { level } -> if Protocol_hash.equal protocol head.protocol_hash then
let level = Int32.succ level in head.proto_level
Lwt.return (Some { Updater.context ; fitness ; timestamp ; 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 = let operations node block =
match block with match block with

View File

@ -44,10 +44,11 @@ type validation_result = {
} }
type rpc_context = { 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 ; context: Context.t ;
level: Int32.t ;
timestamp: Time.t ;
fitness: Fitness.fitness ;
} }
module type PROTOCOL = sig module type PROTOCOL = sig

View File

@ -11,19 +11,6 @@ open Logging.Updater
let (//) = Filename.concat 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 PROTOCOL = Protocol.PROTOCOL
module type REGISTRED_PROTOCOL = sig module type REGISTRED_PROTOCOL = sig
val hash: Protocol_hash.t 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 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 *) (** Version table *)
module VersionTable = Protocol_hash.Table module VersionTable = Protocol_hash.Table

View File

@ -42,10 +42,11 @@ type validation_result = Protocol.validation_result = {
} }
type rpc_context = Protocol.rpc_context = { 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 ; context: Context.t ;
level: Int32.t ;
timestamp: Time.t ;
fitness: Fitness.fitness ;
} }
module type PROTOCOL = Protocol.PROTOCOL module type PROTOCOL = Protocol.PROTOCOL

View File

@ -9,8 +9,11 @@
open Tezos_context open Tezos_context
let rpc_init { Updater.context ; level ; timestamp ; fitness } = let rpc_init rpc_context =
Tezos_context.init ~level ~timestamp ~fitness 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 rpc_services = ref (RPC.empty : Updater.rpc_context RPC.directory)
let register0 s f = let register0 s f =

View File

@ -51,8 +51,8 @@ type validation_result = {
type rpc_context = { type rpc_context = {
block_hash: Block_hash.t ; block_hash: Block_hash.t ;
block_header: raw_block_header ; block_header: raw_block_header ;
operations_list: unit -> Operation_hash.t list list ; operation_hashes: unit -> Operation_hash.t list list Lwt.t ;
operations: unit -> MBytes.t list list ; operations: unit -> raw_operation list list Lwt.t ;
context: Context.t ; context: Context.t ;
} }