Alpha: remove hash from Operation_repr.t
This commit is contained in:
parent
e2af8dbee9
commit
3aef2ed505
@ -98,8 +98,7 @@ let classify_operations (ops: Operation.raw list) =
|
||||
let t = Array.make (List.length Proto_alpha.Main.validation_passes) [] in
|
||||
List.iter
|
||||
(fun op ->
|
||||
let h = Operation.hash_raw op in
|
||||
match Operation.parse h op with
|
||||
match Operation.parse op with
|
||||
| Ok o ->
|
||||
List.iter
|
||||
(fun pass -> t.(pass) <- op :: t.(pass))
|
||||
|
@ -568,7 +568,6 @@ module Vote : sig
|
||||
end
|
||||
|
||||
type operation = {
|
||||
hash: Operation_hash.t ;
|
||||
shell: Operation.shell_header ;
|
||||
contents: proto_operation ;
|
||||
signature: signature option ;
|
||||
@ -654,10 +653,11 @@ module Operation : sig
|
||||
type t = operation
|
||||
val encoding: operation Data_encoding.t
|
||||
|
||||
val hash: operation -> Operation_hash.t
|
||||
val hash_raw: raw -> Operation_hash.t
|
||||
|
||||
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 parse_proto:
|
||||
|
@ -20,7 +20,9 @@ module S = struct
|
||||
~description: "All the operations of the block (fully decoded)."
|
||||
~query: RPC_query.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")
|
||||
|
||||
let header =
|
||||
@ -55,7 +57,9 @@ let () =
|
||||
ctxt.operation_hashes () >>= fun operation_hashes ->
|
||||
ctxt.operations () >>= fun operations ->
|
||||
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
|
||||
end ;
|
||||
register0_fullctxt S.header begin fun { block_header ; _ } () () ->
|
||||
|
@ -10,7 +10,7 @@
|
||||
open Alpha_context
|
||||
|
||||
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:
|
||||
'a #RPC_context.simple -> 'a -> Block_header.t shell_tzresult Lwt.t
|
||||
val priority:
|
||||
|
@ -305,10 +305,10 @@ let apply_anonymous_operation ctxt delegate origination_nonce kind =
|
||||
fail Too_many_faucet
|
||||
|
||||
let apply_operation
|
||||
ctxt delegate pred_block block_prio operation =
|
||||
ctxt delegate pred_block block_prio hash operation =
|
||||
match operation.contents with
|
||||
| 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
|
||||
(fun (ctxt, origination_nonce, fees, rewards) op ->
|
||||
apply_anonymous_operation ctxt delegate origination_nonce op
|
||||
@ -321,7 +321,7 @@ let apply_operation
|
||||
return (ctxt, Contract.originated_contracts origination_nonce, None,
|
||||
fees, rewards)
|
||||
| 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
|
||||
ctxt pred_block block_prio
|
||||
operation origination_nonce op >>=? fun (ctxt, origination_nonce, err,
|
||||
|
@ -132,13 +132,13 @@ module I = struct
|
||||
forged_operation with
|
||||
| None -> Error_monad.fail Operation.Cannot_parse_operation
|
||||
| Some (shell, contents) ->
|
||||
let operation = { hash ; shell ; contents ; signature } in
|
||||
let operation = { shell ; contents ; signature } in
|
||||
let level = Alpha_context.Level.current ctxt in
|
||||
Baking.baking_priorities ctxt level >>=? fun (Misc.LCons (baker_pk, _)) ->
|
||||
let baker_pkh = Ed25519.Public_key.hash baker_pk in
|
||||
let block_prio = 0 in
|
||||
Apply.apply_operation
|
||||
ctxt (Some baker_pkh) pred_block block_prio operation
|
||||
ctxt (Some baker_pkh) pred_block block_prio hash operation
|
||||
>>=? function
|
||||
| (_ctxt, _, Some script_err, _, _) -> Lwt.return (Error script_err)
|
||||
| (_ctxt, contracts, None,_ , _) -> Lwt.return (Ok contracts)
|
||||
@ -480,20 +480,20 @@ module Parse = struct
|
||||
Roll.delegate_pubkey ctxt manager
|
||||
end >>=? fun public_key ->
|
||||
Operation.check_signature public_key
|
||||
{ signature ; shell ; contents ; hash = Operation_hash.zero }
|
||||
{ signature ; shell ; contents }
|
||||
| Sourced_operations (Consensus_operation (Endorsements { level ; slots ; _ })) ->
|
||||
let level = Level.from_raw ctxt level in
|
||||
Baking.check_endorsements_rights ctxt level slots >>=? fun public_key ->
|
||||
Operation.check_signature public_key
|
||||
{ signature ; shell ; contents ; hash = Operation_hash.zero }
|
||||
{ signature ; shell ; contents }
|
||||
| Sourced_operations (Amendment_operation { source ; _ }) ->
|
||||
Roll.delegate_pubkey ctxt source >>=? fun source ->
|
||||
Operation.check_signature source
|
||||
{ signature ; shell ; contents ; hash = Operation_hash.zero }
|
||||
{ signature ; shell ; contents }
|
||||
| Sourced_operations (Dictator_operation _) ->
|
||||
let key = Constants.dictator_pubkey ctxt in
|
||||
Operation.check_signature key
|
||||
{ signature ; shell ; contents ; hash = Operation_hash.zero }
|
||||
{ signature ; shell ; contents }
|
||||
|
||||
end
|
||||
|
||||
@ -501,7 +501,7 @@ module Parse = struct
|
||||
let open Services_registration in
|
||||
register0 S.operations begin fun ctxt () (operations, check) ->
|
||||
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
|
||||
| Some true -> I.check_signature ctxt op.signature op.shell op.contents
|
||||
| Some false | None -> return ()
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
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 max_block_length =
|
||||
@ -118,7 +118,8 @@ let apply_operation ({ mode ; ctxt ; op_count ; _ } as data) operation =
|
||||
predecessor,
|
||||
protocol_data.priority,
|
||||
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) ->
|
||||
let op_count = op_count + 1 in
|
||||
Lwt.return Alpha_context.Tez.(fees >>? (+?) data.fees) >>=? fun fees ->
|
||||
|
@ -17,7 +17,6 @@ type raw = Operation.t = {
|
||||
let raw_encoding = Operation.encoding
|
||||
|
||||
type operation = {
|
||||
hash: Operation_hash.t ;
|
||||
shell: Operation.shell_header ;
|
||||
contents: proto_operation ;
|
||||
signature: Ed25519.Signature.t option ;
|
||||
@ -356,15 +355,13 @@ type error += Cannot_parse_operation
|
||||
let encoding =
|
||||
let open Data_encoding in
|
||||
conv
|
||||
(fun { hash ; shell ; contents ; signature } ->
|
||||
(hash, (shell, (contents, signature))))
|
||||
(fun (hash, (shell, (contents, signature))) ->
|
||||
{ hash ; shell ; contents ; signature })
|
||||
(fun { shell ; contents ; signature } ->
|
||||
(shell, (contents, signature)))
|
||||
(fun (shell, (contents, signature)) ->
|
||||
{ shell ; contents ; signature })
|
||||
(merge_objs
|
||||
(obj1 (req "hash" Operation_hash.encoding))
|
||||
(merge_objs
|
||||
Operation.shell_header_encoding
|
||||
Encoding.signed_proto_operation_encoding))
|
||||
Operation.shell_header_encoding
|
||||
Encoding.signed_proto_operation_encoding)
|
||||
|
||||
let () =
|
||||
register_error_kind
|
||||
@ -379,12 +376,12 @@ let () =
|
||||
(function Cannot_parse_operation -> Some () | _ -> None)
|
||||
(fun () -> Cannot_parse_operation)
|
||||
|
||||
let parse hash (op: Operation.t) =
|
||||
let parse (op: Operation.t) =
|
||||
match Data_encoding.Binary.of_bytes
|
||||
Encoding.signed_proto_operation_encoding
|
||||
op.proto with
|
||||
| Some (contents, signature) ->
|
||||
ok { hash ; shell = op.shell ; contents ; signature }
|
||||
ok { shell = op.shell ; contents ; signature }
|
||||
| None -> error Cannot_parse_operation
|
||||
|
||||
let acceptable_passes op =
|
||||
@ -425,7 +422,7 @@ let forge shell proto =
|
||||
Data_encoding.Binary.to_bytes
|
||||
Encoding.unsigned_operation_encoding (shell, proto)
|
||||
|
||||
let check_signature key { shell ; contents ; signature } =
|
||||
let check_signature key { shell ; contents ; signature } =
|
||||
match contents, signature with
|
||||
| Anonymous_operations _, _ -> return ()
|
||||
| Sourced_operations _, None ->
|
||||
@ -444,6 +441,12 @@ let parse_proto bytes =
|
||||
| Some (proto, signature) -> return (proto, signature)
|
||||
| None -> fail Cannot_parse_operation
|
||||
|
||||
include Encoding
|
||||
|
||||
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
|
||||
|
@ -17,7 +17,6 @@ type raw = Operation.t = {
|
||||
val raw_encoding: raw Data_encoding.t
|
||||
|
||||
type operation = {
|
||||
hash: Operation_hash.t ;
|
||||
shell: Operation.shell_header ;
|
||||
contents: proto_operation ;
|
||||
signature: Ed25519.Signature.t option ;
|
||||
@ -97,9 +96,9 @@ type error += Cannot_parse_operation (* `Branch *)
|
||||
val encoding: operation Data_encoding.t
|
||||
|
||||
val hash_raw: raw -> Operation_hash.t
|
||||
val hash: operation -> Operation_hash.t
|
||||
|
||||
val parse:
|
||||
Operation_hash.t -> Operation.t -> operation tzresult
|
||||
val parse: Operation.t -> operation tzresult
|
||||
|
||||
val acceptable_passes: operation -> int list
|
||||
|
||||
|
@ -13,11 +13,13 @@ let operation
|
||||
~tc ?(baker: Helpers_account.t option) ?(src: Helpers_account.t option)
|
||||
pred_block_hash op_sh proto_op =
|
||||
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
|
||||
tc
|
||||
(Option.map ~f:(fun x -> x.Helpers_account.hpub) baker)
|
||||
pred_block_hash
|
||||
0
|
||||
hash
|
||||
operation >>=? fun (tc, contracts, err, _fees, _rewards) ->
|
||||
return ((contracts, err), tc)
|
||||
|
||||
|
@ -122,12 +122,8 @@ let main_of_proto (src: Helpers_account.t) operation_header protocol_operation =
|
||||
|
||||
let apply_of_proto
|
||||
(source: Helpers_account.t option) operation_header protocol_operation =
|
||||
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
|
||||
let (_proto, signature) = sign source operation_header protocol_operation in
|
||||
{
|
||||
hash ;
|
||||
shell = operation_header ;
|
||||
contents = protocol_operation ;
|
||||
signature
|
||||
|
@ -26,7 +26,8 @@ let execute_code_pred
|
||||
let op_header = Helpers_block.get_op_header_res pred in
|
||||
let apply_op = Helpers_operation.apply_of_proto
|
||||
(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 gaz = Gas.of_int (Alpha_context.Constants.max_gas tc) in
|
||||
let return = Script_interpreter.execute
|
||||
|
Loading…
Reference in New Issue
Block a user