Shell/RPC: preapply now take a list of list of operations.

Progress towards the multipass validator.
This commit is contained in:
Grégoire Henry 2017-12-05 15:17:57 +01:00 committed by Grégoire
parent 46d7830af4
commit e850648894
7 changed files with 30 additions and 20 deletions

View File

@ -69,12 +69,12 @@ module Blocks = struct
type preapply_param = Services.Blocks.preapply_param = { type preapply_param = Services.Blocks.preapply_param = {
timestamp: Time.t ; timestamp: Time.t ;
proto_header: MBytes.t ; proto_header: MBytes.t ;
operations: Operation.t list ; operations: Operation.t list list ;
sort_operations: bool ; sort_operations: bool ;
} }
type preapply_result = Services.Blocks.preapply_result = { type preapply_result = Services.Blocks.preapply_result = {
shell_header: Block_header.shell_header ; shell_header: Block_header.shell_header ;
operations: error Preapply_result.t ; operations: error Preapply_result.t list ;
} }
let net_id cctxt h = let net_id cctxt h =
call_service1 cctxt Services.Blocks.net_id h () call_service1 cctxt Services.Blocks.net_id h ()

View File

@ -113,7 +113,7 @@ module Blocks : sig
type preapply_result = { type preapply_result = {
shell_header: Block_header.shell_header ; shell_header: Block_header.shell_header ;
operations: error Preapply_result.t ; operations: error Preapply_result.t list ;
} }
val preapply: val preapply:
@ -122,7 +122,7 @@ module Blocks : sig
?timestamp:Time.t -> ?timestamp:Time.t ->
?sort:bool -> ?sort:bool ->
proto_header:MBytes.t -> proto_header:MBytes.t ->
Operation.t list -> preapply_result tzresult Lwt.t Operation.t list list -> preapply_result tzresult Lwt.t
end end

View File

@ -158,8 +158,9 @@ let forge_block cctxt block
let request = List.length operations in let request = List.length operations in
let proto_header = forge_faked_proto_header ~priority ~seed_nonce_hash in let proto_header = forge_faked_proto_header ~priority ~seed_nonce_hash in
Client_node_rpcs.Blocks.preapply Client_node_rpcs.Blocks.preapply
cctxt block ~timestamp ~sort ~proto_header operations >>=? cctxt block ~timestamp ~sort ~proto_header [operations] >>=?
fun { operations = result ; shell_header } -> fun { operations = result ; shell_header } ->
let result = List.hd result in
let valid = List.length result.applied in let valid = List.length result.applied in
lwt_log_info "Found %d valid operations (%d refused) for timestamp %a" lwt_log_info "Found %d valid operations (%d refused) for timestamp %a"
valid (request - valid) valid (request - valid)
@ -446,13 +447,14 @@ let bake (cctxt : Client_commands.full_context) state =
let proto_header = let proto_header =
forge_faked_proto_header ~priority ~seed_nonce_hash in forge_faked_proto_header ~priority ~seed_nonce_hash in
Client_node_rpcs.Blocks.preapply cctxt block Client_node_rpcs.Blocks.preapply cctxt block
~timestamp ~sort:true ~proto_header operations >>= function ~timestamp ~sort:true ~proto_header [operations] >>= function
| Error errs -> | Error errs ->
lwt_log_error "Error while prevalidating operations:\n%a" lwt_log_error "Error while prevalidating operations:\n%a"
pp_print_error pp_print_error
errs >>= fun () -> errs >>= fun () ->
return None return None
| Ok { operations ; shell_header } -> | Ok { operations ; shell_header } ->
let operations = List.hd operations in
lwt_debug lwt_debug
"Computed condidate block after %a (slot %d): %d/%d fitness: %a" "Computed condidate block after %a (slot %d): %d/%d fitness: %a"
Block_hash.pp_short bi.hash priority Block_hash.pp_short bi.hash priority

View File

@ -305,7 +305,7 @@ module Blocks = struct
type preapply_param = { type preapply_param = {
timestamp: Time.t ; timestamp: Time.t ;
proto_header: MBytes.t ; proto_header: MBytes.t ;
operations: Operation.t list ; operations: Operation.t list list ;
sort_operations: bool ; sort_operations: bool ;
} }
@ -318,12 +318,12 @@ module Blocks = struct
(obj4 (obj4
(req "timestamp" Time.encoding) (req "timestamp" Time.encoding)
(req "proto_header" bytes) (req "proto_header" bytes)
(req "operations" (list (dynamic_size Operation.encoding))) (req "operations" (list (dynamic_size (list (dynamic_size Operation.encoding)))))
(dft "sort_operations" bool false))) (dft "sort_operations" bool false)))
type preapply_result = { type preapply_result = {
shell_header: Block_header.shell_header ; shell_header: Block_header.shell_header ;
operations: error Preapply_result.t ; operations: error Preapply_result.t list ;
} }
let preapply_result_encoding = let preapply_result_encoding =
@ -335,7 +335,7 @@ module Blocks = struct
(obj2 (obj2
(req "shell_header" Block_header.shell_header_encoding) (req "shell_header" Block_header.shell_header_encoding)
(req "operations" (req "operations"
(Preapply_result.encoding Error.encoding)))) (list (Preapply_result.encoding Error.encoding)))))
let preapply = let preapply =
RPC_service.post_service RPC_service.post_service

View File

@ -120,13 +120,13 @@ module Blocks : sig
type preapply_param = { type preapply_param = {
timestamp: Time.t ; timestamp: Time.t ;
proto_header: MBytes.t ; proto_header: MBytes.t ;
operations: Operation.t list ; operations: Operation.t list list ;
sort_operations: bool ; sort_operations: bool ;
} }
type preapply_result = { type preapply_result = {
shell_header: Block_header.shell_header ; shell_header: Block_header.shell_header ;
operations: error Preapply_result.t ; operations: error Preapply_result.t list ;
} }
val preapply: val preapply:
([ `POST ], unit, ([ `POST ], unit,

View File

@ -475,12 +475,20 @@ module RPC = struct
end >>=? fun predecessor -> end >>=? fun predecessor ->
Prevalidation.start_prevalidation Prevalidation.start_prevalidation
~proto_header ~predecessor ~timestamp () >>=? fun validation_state -> ~proto_header ~predecessor ~timestamp () >>=? fun validation_state ->
let ops = List.map (fun x -> Operation.hash x, x) ops in let ops = List.map (List.map (fun x -> Operation.hash x, x)) ops in
Prevalidation.prevalidate Lwt_list.fold_left_s
validation_state ~sort ops >>= fun (validation_state, r) -> (fun (validation_state, rs) ops ->
Prevalidation.prevalidate
validation_state ~sort ops >>= fun (validation_state, r) ->
Lwt.return (validation_state, rs @ [r]))
(validation_state, []) ops >>= fun (validation_state, rs) ->
let operations_hash = let operations_hash =
Operation_list_list_hash.compute Operation_list_list_hash.compute
[Operation_list_hash.compute (List.map fst r.applied)] in (List.map
(fun r ->
Operation_list_hash.compute
(List.map fst r.Preapply_result.applied))
rs) in
Prevalidation.end_prevalidation Prevalidation.end_prevalidation
validation_state >>=? fun { fitness ; context } -> validation_state >>=? fun { fitness ; context } ->
let pred_shell_header = State.Block.shell_header predecessor in let pred_shell_header = State.Block.shell_header predecessor in
@ -496,11 +504,11 @@ module RPC = struct
proto_level ; proto_level ;
predecessor = State.Block.hash predecessor ; predecessor = State.Block.hash predecessor ;
timestamp ; timestamp ;
validation_passes = 1 ; validation_passes = List.length rs ;
operations_hash ; operations_hash ;
fitness ; fitness ;
} in } in
return (shell_header, r) return (shell_header, rs)
let complete node ?block str = let complete node ?block str =
match block with match block with

View File

@ -94,8 +94,8 @@ module RPC : sig
val preapply: val preapply:
t -> block -> t -> block ->
timestamp:Time.t -> proto_header:MBytes.t -> timestamp:Time.t -> proto_header:MBytes.t ->
sort_operations:bool -> Operation.t list -> sort_operations:bool -> Operation.t list list ->
(Block_header.shell_header * error Preapply_result.t) tzresult Lwt.t (Block_header.shell_header * error Preapply_result.t list) tzresult Lwt.t
val context_dir: val context_dir:
t -> block -> 'a RPC_directory.t option Lwt.t t -> block -> 'a RPC_directory.t option Lwt.t