Alpha: remove hash from Operation_repr.t

This commit is contained in:
Grégoire Henry 2018-03-15 10:28:41 +01:00 committed by Benjamin Canou
parent e2af8dbee9
commit 3aef2ed505
12 changed files with 47 additions and 42 deletions

View File

@ -98,8 +98,7 @@ let classify_operations (ops: Operation.raw list) =
let t = Array.make (List.length Proto_alpha.Main.validation_passes) [] in let t = Array.make (List.length Proto_alpha.Main.validation_passes) [] in
List.iter List.iter
(fun op -> (fun op ->
let h = Operation.hash_raw op in match Operation.parse op with
match Operation.parse h op with
| Ok o -> | Ok o ->
List.iter List.iter
(fun pass -> t.(pass) <- op :: t.(pass)) (fun pass -> t.(pass) <- op :: t.(pass))

View File

@ -568,7 +568,6 @@ module Vote : sig
end end
type operation = { type operation = {
hash: Operation_hash.t ;
shell: Operation.shell_header ; shell: Operation.shell_header ;
contents: proto_operation ; contents: proto_operation ;
signature: signature option ; signature: signature option ;
@ -654,10 +653,11 @@ module Operation : sig
type t = operation type t = operation
val encoding: operation Data_encoding.t val encoding: operation Data_encoding.t
val hash: operation -> Operation_hash.t
val hash_raw: raw -> Operation_hash.t val hash_raw: raw -> Operation_hash.t
type error += Cannot_parse_operation (* `Branch *) type error += Cannot_parse_operation (* `Branch *)
val parse: Operation_hash.t -> Operation.t -> operation tzresult val parse: Operation.t -> operation tzresult
val acceptable_passes: operation -> int list val acceptable_passes: operation -> int list
val parse_proto: val parse_proto:

View File

@ -20,7 +20,9 @@ module S = struct
~description: "All the operations of the block (fully decoded)." ~description: "All the operations of the block (fully decoded)."
~query: RPC_query.empty ~query: RPC_query.empty
~input: empty ~input: empty
~output: (list (list (dynamic_size Operation.encoding))) ~output: (list (list (merge_objs
(obj1 (req "hash" Operation_hash.encoding))
(dynamic_size Operation.encoding))))
RPC_path.(custom_root / "operations") RPC_path.(custom_root / "operations")
let header = let header =
@ -55,7 +57,9 @@ let () =
ctxt.operation_hashes () >>= fun operation_hashes -> ctxt.operation_hashes () >>= fun operation_hashes ->
ctxt.operations () >>= fun operations -> ctxt.operations () >>= fun operations ->
map2_s map2_s
(map2_s (fun x y -> Lwt.return (Operation.parse x y))) (map2_s (fun h op ->
Lwt.return (Operation.parse op) >>=? fun op ->
return (h, op)))
operation_hashes operations operation_hashes operations
end ; end ;
register0_fullctxt S.header begin fun { block_header ; _ } () () -> register0_fullctxt S.header begin fun { block_header ; _ } () () ->

View File

@ -10,7 +10,7 @@
open Alpha_context open Alpha_context
val operations: val operations:
'a #RPC_context.simple -> 'a -> Operation.t list list shell_tzresult Lwt.t 'a #RPC_context.simple -> 'a -> (Operation_hash.t * Operation.t) list list shell_tzresult Lwt.t
val header: val header:
'a #RPC_context.simple -> 'a -> Block_header.t shell_tzresult Lwt.t 'a #RPC_context.simple -> 'a -> Block_header.t shell_tzresult Lwt.t
val priority: val priority:

View File

@ -305,10 +305,10 @@ let apply_anonymous_operation ctxt delegate origination_nonce kind =
fail Too_many_faucet fail Too_many_faucet
let apply_operation let apply_operation
ctxt delegate pred_block block_prio operation = ctxt delegate pred_block block_prio hash operation =
match operation.contents with match operation.contents with
| Anonymous_operations ops -> | Anonymous_operations ops ->
let origination_nonce = Contract.initial_origination_nonce operation.hash in let origination_nonce = Contract.initial_origination_nonce hash in
fold_left_s fold_left_s
(fun (ctxt, origination_nonce, fees, rewards) op -> (fun (ctxt, origination_nonce, fees, rewards) op ->
apply_anonymous_operation ctxt delegate origination_nonce op apply_anonymous_operation ctxt delegate origination_nonce op
@ -321,7 +321,7 @@ let apply_operation
return (ctxt, Contract.originated_contracts origination_nonce, None, return (ctxt, Contract.originated_contracts origination_nonce, None,
fees, rewards) fees, rewards)
| Sourced_operations op -> | Sourced_operations op ->
let origination_nonce = Contract.initial_origination_nonce operation.hash in let origination_nonce = Contract.initial_origination_nonce hash in
apply_sourced_operation apply_sourced_operation
ctxt pred_block block_prio ctxt pred_block block_prio
operation origination_nonce op >>=? fun (ctxt, origination_nonce, err, operation origination_nonce op >>=? fun (ctxt, origination_nonce, err,

View File

@ -132,13 +132,13 @@ module I = struct
forged_operation with forged_operation with
| None -> Error_monad.fail Operation.Cannot_parse_operation | None -> Error_monad.fail Operation.Cannot_parse_operation
| Some (shell, contents) -> | Some (shell, contents) ->
let operation = { hash ; shell ; contents ; signature } in let operation = { shell ; contents ; signature } in
let level = Alpha_context.Level.current ctxt in let level = Alpha_context.Level.current ctxt in
Baking.baking_priorities ctxt level >>=? fun (Misc.LCons (baker_pk, _)) -> Baking.baking_priorities ctxt level >>=? fun (Misc.LCons (baker_pk, _)) ->
let baker_pkh = Ed25519.Public_key.hash baker_pk in let baker_pkh = Ed25519.Public_key.hash baker_pk in
let block_prio = 0 in let block_prio = 0 in
Apply.apply_operation Apply.apply_operation
ctxt (Some baker_pkh) pred_block block_prio operation ctxt (Some baker_pkh) pred_block block_prio hash operation
>>=? function >>=? function
| (_ctxt, _, Some script_err, _, _) -> Lwt.return (Error script_err) | (_ctxt, _, Some script_err, _, _) -> Lwt.return (Error script_err)
| (_ctxt, contracts, None,_ , _) -> Lwt.return (Ok contracts) | (_ctxt, contracts, None,_ , _) -> Lwt.return (Ok contracts)
@ -480,20 +480,20 @@ module Parse = struct
Roll.delegate_pubkey ctxt manager Roll.delegate_pubkey ctxt manager
end >>=? fun public_key -> end >>=? fun public_key ->
Operation.check_signature public_key Operation.check_signature public_key
{ signature ; shell ; contents ; hash = Operation_hash.zero } { signature ; shell ; contents }
| Sourced_operations (Consensus_operation (Endorsements { level ; slots ; _ })) -> | Sourced_operations (Consensus_operation (Endorsements { level ; slots ; _ })) ->
let level = Level.from_raw ctxt level in let level = Level.from_raw ctxt level in
Baking.check_endorsements_rights ctxt level slots >>=? fun public_key -> Baking.check_endorsements_rights ctxt level slots >>=? fun public_key ->
Operation.check_signature public_key Operation.check_signature public_key
{ signature ; shell ; contents ; hash = Operation_hash.zero } { signature ; shell ; contents }
| Sourced_operations (Amendment_operation { source ; _ }) -> | Sourced_operations (Amendment_operation { source ; _ }) ->
Roll.delegate_pubkey ctxt source >>=? fun source -> Roll.delegate_pubkey ctxt source >>=? fun source ->
Operation.check_signature source Operation.check_signature source
{ signature ; shell ; contents ; hash = Operation_hash.zero } { signature ; shell ; contents }
| Sourced_operations (Dictator_operation _) -> | Sourced_operations (Dictator_operation _) ->
let key = Constants.dictator_pubkey ctxt in let key = Constants.dictator_pubkey ctxt in
Operation.check_signature key Operation.check_signature key
{ signature ; shell ; contents ; hash = Operation_hash.zero } { signature ; shell ; contents }
end end
@ -501,7 +501,7 @@ module Parse = struct
let open Services_registration in let open Services_registration in
register0 S.operations begin fun ctxt () (operations, check) -> register0 S.operations begin fun ctxt () (operations, check) ->
map_s begin fun raw -> map_s begin fun raw ->
Lwt.return (Operation.parse (Operation.hash_raw raw) raw) >>=? fun op -> Lwt.return (Operation.parse raw) >>=? fun op ->
begin match check with begin match check with
| Some true -> I.check_signature ctxt op.signature op.shell op.contents | Some true -> I.check_signature ctxt op.signature op.shell op.contents
| Some false | None -> return () | Some false | None -> return ()

View File

@ -11,7 +11,7 @@
type operation = Alpha_context.operation type operation = Alpha_context.operation
let parse_operation = Alpha_context.Operation.parse let parse_operation _hash op = Alpha_context.Operation.parse op
let acceptable_passes = Alpha_context.Operation.acceptable_passes let acceptable_passes = Alpha_context.Operation.acceptable_passes
let max_block_length = let max_block_length =
@ -118,7 +118,8 @@ let apply_operation ({ mode ; ctxt ; op_count ; _ } as data) operation =
predecessor, predecessor,
protocol_data.priority, protocol_data.priority,
Some baker in Some baker in
Apply.apply_operation ctxt baker pred_block block_prio operation Apply.apply_operation ctxt baker pred_block block_prio
(Alpha_context.Operation.hash operation) operation
>>=? fun (ctxt, _contracts, _ignored_script_error, fees, rewards) -> >>=? fun (ctxt, _contracts, _ignored_script_error, fees, rewards) ->
let op_count = op_count + 1 in let op_count = op_count + 1 in
Lwt.return Alpha_context.Tez.(fees >>? (+?) data.fees) >>=? fun fees -> Lwt.return Alpha_context.Tez.(fees >>? (+?) data.fees) >>=? fun fees ->

View File

@ -17,7 +17,6 @@ type raw = Operation.t = {
let raw_encoding = Operation.encoding let raw_encoding = Operation.encoding
type operation = { type operation = {
hash: Operation_hash.t ;
shell: Operation.shell_header ; shell: Operation.shell_header ;
contents: proto_operation ; contents: proto_operation ;
signature: Ed25519.Signature.t option ; signature: Ed25519.Signature.t option ;
@ -356,15 +355,13 @@ type error += Cannot_parse_operation
let encoding = let encoding =
let open Data_encoding in let open Data_encoding in
conv conv
(fun { hash ; shell ; contents ; signature } -> (fun { shell ; contents ; signature } ->
(hash, (shell, (contents, signature)))) (shell, (contents, signature)))
(fun (hash, (shell, (contents, signature))) -> (fun (shell, (contents, signature)) ->
{ hash ; shell ; contents ; signature }) { shell ; contents ; signature })
(merge_objs
(obj1 (req "hash" Operation_hash.encoding))
(merge_objs (merge_objs
Operation.shell_header_encoding Operation.shell_header_encoding
Encoding.signed_proto_operation_encoding)) Encoding.signed_proto_operation_encoding)
let () = let () =
register_error_kind register_error_kind
@ -379,12 +376,12 @@ let () =
(function Cannot_parse_operation -> Some () | _ -> None) (function Cannot_parse_operation -> Some () | _ -> None)
(fun () -> Cannot_parse_operation) (fun () -> Cannot_parse_operation)
let parse hash (op: Operation.t) = let parse (op: Operation.t) =
match Data_encoding.Binary.of_bytes match Data_encoding.Binary.of_bytes
Encoding.signed_proto_operation_encoding Encoding.signed_proto_operation_encoding
op.proto with op.proto with
| Some (contents, signature) -> | Some (contents, signature) ->
ok { hash ; shell = op.shell ; contents ; signature } ok { shell = op.shell ; contents ; signature }
| None -> error Cannot_parse_operation | None -> error Cannot_parse_operation
let acceptable_passes op = let acceptable_passes op =
@ -444,6 +441,12 @@ let parse_proto bytes =
| Some (proto, signature) -> return (proto, signature) | Some (proto, signature) -> return (proto, signature)
| None -> fail Cannot_parse_operation | None -> fail Cannot_parse_operation
include Encoding
let hash_raw = Operation.hash let hash_raw = Operation.hash
let hash o =
let proto =
Data_encoding.Binary.to_bytes
Encoding.signed_proto_operation_encoding
(o.contents, o.signature) in
Operation.hash { shell = o.shell ; proto }
include Encoding

View File

@ -17,7 +17,6 @@ type raw = Operation.t = {
val raw_encoding: raw Data_encoding.t val raw_encoding: raw Data_encoding.t
type operation = { type operation = {
hash: Operation_hash.t ;
shell: Operation.shell_header ; shell: Operation.shell_header ;
contents: proto_operation ; contents: proto_operation ;
signature: Ed25519.Signature.t option ; signature: Ed25519.Signature.t option ;
@ -97,9 +96,9 @@ type error += Cannot_parse_operation (* `Branch *)
val encoding: operation Data_encoding.t val encoding: operation Data_encoding.t
val hash_raw: raw -> Operation_hash.t val hash_raw: raw -> Operation_hash.t
val hash: operation -> Operation_hash.t
val parse: val parse: Operation.t -> operation tzresult
Operation_hash.t -> Operation.t -> operation tzresult
val acceptable_passes: operation -> int list val acceptable_passes: operation -> int list

View File

@ -13,11 +13,13 @@ let operation
~tc ?(baker: Helpers_account.t option) ?(src: Helpers_account.t option) ~tc ?(baker: Helpers_account.t option) ?(src: Helpers_account.t option)
pred_block_hash op_sh proto_op = pred_block_hash op_sh proto_op =
return @@ Helpers_operation.apply_of_proto src op_sh proto_op >>=? fun operation -> return @@ Helpers_operation.apply_of_proto src op_sh proto_op >>=? fun operation ->
let hash = Proto_alpha.Alpha_context.Operation.hash operation in
Proto_alpha.Apply.apply_operation Proto_alpha.Apply.apply_operation
tc tc
(Option.map ~f:(fun x -> x.Helpers_account.hpub) baker) (Option.map ~f:(fun x -> x.Helpers_account.hpub) baker)
pred_block_hash pred_block_hash
0 0
hash
operation >>=? fun (tc, contracts, err, _fees, _rewards) -> operation >>=? fun (tc, contracts, err, _fees, _rewards) ->
return ((contracts, err), tc) return ((contracts, err), tc)

View File

@ -122,12 +122,8 @@ let main_of_proto (src: Helpers_account.t) operation_header protocol_operation =
let apply_of_proto let apply_of_proto
(source: Helpers_account.t option) operation_header protocol_operation = (source: Helpers_account.t option) operation_header protocol_operation =
let (proto, signature) = sign source operation_header protocol_operation in let (_proto, signature) = sign source operation_header protocol_operation in
let data_operation: Tezos_base.Operation.t =
{shell = operation_header ; proto} in
let hash = Tezos_base.Operation.hash data_operation in
{ {
hash ;
shell = operation_header ; shell = operation_header ;
contents = protocol_operation ; contents = protocol_operation ;
signature signature

View File

@ -26,7 +26,8 @@ let execute_code_pred
let op_header = Helpers_block.get_op_header_res pred in let op_header = Helpers_block.get_op_header_res pred in
let apply_op = Helpers_operation.apply_of_proto let apply_op = Helpers_operation.apply_of_proto
(Some op) op_header dummy_protop in (Some op) op_header dummy_protop in
let dummy_nonce = Contract.initial_origination_nonce apply_op.hash in let hash = Operation.hash apply_op in
let dummy_nonce = Contract.initial_origination_nonce hash in
let amount = Tez.zero in let amount = Tez.zero in
let gaz = Gas.of_int (Alpha_context.Constants.max_gas tc) in let gaz = Gas.of_int (Alpha_context.Constants.max_gas tc) in
let return = Script_interpreter.execute let return = Script_interpreter.execute