From 3293d8351d49907e0230cdc8c55d6c4252220ab4 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 12:33:57 +0200 Subject: [PATCH 1/3] Proto: originated_contracts are originated contracts --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/apply.ml | 3 +++ src/proto_alpha/lib_protocol/contract_repr.ml | 2 +- src/proto_alpha/lib_protocol/contract_repr.mli | 2 +- src/proto_alpha/lib_protocol/contract_storage.ml | 2 +- src/proto_alpha/lib_protocol/contract_storage.mli | 2 +- .../lib_protocol/test/unit/test_destination_repr.ml | 1 + 7 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 4ff360e07f39..1afc764720de 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1528,7 +1528,7 @@ module Contract : sig context -> (context * Contract_hash.t) tzresult val originated_from_current_nonce : - since:context -> until:context -> t list tzresult Lwt.t + since:context -> until:context -> Contract_hash.t list tzresult Lwt.t val get_frozen_bonds : context -> t -> Tez.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index d83506eafd44..424f5a96a116 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -941,6 +941,9 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract_hash ~amount >>=? fun (ctxt, new_size, contract_paid_storage_size_diff) -> Contract.originated_from_current_nonce ~since:before_operation ~until:ctxt >>=? fun originated_contracts -> + let originated_contracts = + List.map (fun c -> Contract.Originated c) originated_contracts + in Lwt.return ( Script_cache.update ctxt diff --git a/src/proto_alpha/lib_protocol/contract_repr.ml b/src/proto_alpha/lib_protocol/contract_repr.ml index 512b8993c0dd..20045646df69 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.ml +++ b/src/proto_alpha/lib_protocol/contract_repr.ml @@ -194,7 +194,7 @@ let originated_contracts if Compare.Int32.(origination_index < first) then acc else let origination_nonce = {origination_nonce with origination_index} in - let acc = originated_contract origination_nonce :: acc in + let acc = Contract_hash.of_nonce origination_nonce :: acc in contracts acc (Int32.pred origination_index) in contracts [] (Int32.pred last) diff --git a/src/proto_alpha/lib_protocol/contract_repr.mli b/src/proto_alpha/lib_protocol/contract_repr.mli index ab76bee991e8..61d57acf48a1 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.mli +++ b/src/proto_alpha/lib_protocol/contract_repr.mli @@ -57,7 +57,7 @@ val originated_contract : Origination_nonce.t -> t must be the same or it will fail with an [assert]. [since] < [until] or the returned list is empty *) val originated_contracts : - since:Origination_nonce.t -> until:Origination_nonce.t -> t list + since:Origination_nonce.t -> until:Origination_nonce.t -> Contract_hash.t list (** {2 Human readable notation} *) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 3f82716ae57c..8fc19e17cc91 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -474,7 +474,7 @@ let originated_from_current_nonce ~since:ctxt_since ~until:ctxt_until = Raw_context.get_origination_nonce ctxt_since >>?= fun since -> Raw_context.get_origination_nonce ctxt_until >>?= fun until -> List.filter_s - (fun contract -> exists ctxt_until contract) + (fun contract -> exists ctxt_until (Contract_repr.Originated contract)) (Contract_repr.originated_contracts ~since ~until) >|= ok diff --git a/src/proto_alpha/lib_protocol/contract_storage.mli b/src/proto_alpha/lib_protocol/contract_storage.mli index 344e1409caa4..7c92fff7e9f0 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.mli +++ b/src/proto_alpha/lib_protocol/contract_storage.mli @@ -155,7 +155,7 @@ val fresh_contract_from_current_nonce : val originated_from_current_nonce : since:Raw_context.t -> until:Raw_context.t -> - Contract_repr.t list tzresult Lwt.t + Contract_hash.t list tzresult Lwt.t val init : Raw_context.t -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml index f11acbd8b41c..78153e63ed95 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_destination_repr.ml @@ -49,6 +49,7 @@ let contracts = in let until = incr_n_times since 5 in Contract_repr.originated_contracts ~since ~until + |> List.map (fun c -> Contract_repr.Originated c) let dest x = Destination_repr.Contract x -- GitLab From c181ee53332d20cbadaf17cbf50fc2d5e302286f Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 12:59:19 +0200 Subject: [PATCH 2/3] Proto: preorigination is an originated contract --- src/proto_alpha/lib_protocol/apply.ml | 4 ++-- src/proto_alpha/lib_protocol/script_interpreter.ml | 6 ++---- src/proto_alpha/lib_protocol/script_interpreter_defs.ml | 8 +++----- src/proto_alpha/lib_protocol/script_typed_ir.ml | 2 +- src/proto_alpha/lib_protocol/script_typed_ir.mli | 2 +- .../test/integration/michelson/test_ticket_accounting.ml | 2 +- .../integration/michelson/test_ticket_operations_diff.ml | 2 +- src/proto_alpha/lib_protocol/ticket_operations_diff.ml | 3 ++- 8 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 424f5a96a116..5c07ba972685 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1207,7 +1207,7 @@ let apply_internal_manager_operation_content : | Origination { origination = {delegate; script; credit}; - preorigination = contract; + preorigination; storage_type; storage; } -> @@ -1221,7 +1221,7 @@ let apply_internal_manager_operation_content : ~storage_type ~storage ~unparsed_code - ~contract + ~contract:(Contract.Originated preorigination) ~delegate ~source ~credit diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 65658d156390..1efa10a6568e 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1136,10 +1136,8 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let credit, (init, stack) = stack in create_contract g gas storage_type code delegate credit init >>=? fun (res, contract, ctxt, gas) -> - let stack = - ( {destination = Contract contract; entrypoint = Entrypoint.default}, - stack ) - in + let destination = Destination.Contract (Originated contract) in + let stack = ({destination; entrypoint = Entrypoint.default}, stack) in (step [@ocaml.tailcall]) (ctxt, sc) gas k ks res stack | ISet_delegate (_, k) -> let delegate = accu in diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index 91aca747c5ca..e5647d2a096e 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -647,8 +647,7 @@ let create_contract (ctxt, sc) gas storage_type code delegate credit init = Gas.consume ctxt (Script.strip_locations_cost storage) >>?= fun ctxt -> let storage = Micheline.strip_locations storage in Contract.fresh_contract_from_current_nonce ctxt - >>?= fun (ctxt, contract_hash) -> - let contract = Contract.Originated contract_hash in + >>?= fun (ctxt, preorigination) -> let origination = { credit; @@ -658,14 +657,13 @@ let create_contract (ctxt, sc) gas storage_type code delegate credit init = } in let operation = - Origination - {origination; preorigination = contract; storage_type; storage = init} + Origination {origination; preorigination; storage_type; storage = init} in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let piop = Internal_operation {source = sc.self; operation; nonce} in let res = {piop; lazy_storage_diff} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in - return (res, contract, ctxt, gas) + return (res, preorigination, ctxt, gas) (* [unpack ctxt ty bytes] deserialize [bytes] into a value of type [ty]. *) let unpack ctxt ~ty ~bytes = diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 5e6b8a25d58f..2d474f7207e7 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1386,7 +1386,7 @@ and 'kind manager_operation = -> Kind.transaction manager_operation | Origination : { origination : Alpha_context.origination; - preorigination : Contract.t; + preorigination : Contract_hash.t; storage_type : ('storage, _) ty; storage : 'storage; } diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index 0a89fdab7d0d..c6cdfdd5929f 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1519,7 +1519,7 @@ and 'kind manager_operation = -> Kind.transaction manager_operation | Origination : { origination : Alpha_context.origination; - preorigination : Contract.t; + preorigination : Contract_hash.t; storage_type : ('storage, _) ty; storage : 'storage; } diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml index addca9869df9..214479f06e71 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml @@ -353,7 +353,7 @@ let origination_operation ctxt ~src ~script:(code, storage) ~orig_contract = Origination { origination = {delegate = None; script; credit = Tez.one}; - preorigination = Contract.Originated orig_contract; + preorigination = orig_contract; storage_type; storage; }; diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index 433bcd78f789..92117269d402 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -256,7 +256,7 @@ let origination_operation block ~src ~baker ~script ~storage ~forges_tickets = Origination { origination = {delegate = None; script; credit = Tez.one}; - preorigination = Contract.Originated orig_contract; + preorigination = orig_contract; storage_type; storage; }; diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 737deb72c42a..86a470bbbd3c 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -233,7 +233,8 @@ let tickets_of_origination ctxt ~preorigination ~storage_type ~storage = >>?= fun (has_tickets, ctxt) -> Ticket_scanner.tickets_of_value ctxt ~include_lazy:true has_tickets storage >|=? fun (tickets, ctxt) -> - (Some {tickets; destination = Destination.Contract preorigination}, ctxt) + let destination = Destination.Contract (Originated preorigination) in + (Some {tickets; destination}, ctxt) let tickets_of_operation ctxt (Script_typed_ir.Internal_operation {source = _; operation; nonce = _}) = -- GitLab From ec7aff0e395cc1f2beda3b3f286bea28722e5a32 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 13:03:16 +0200 Subject: [PATCH 3/3] Proto/Apply: apply_origination expects an originated contract --- src/proto_alpha/lib_protocol/apply.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 5c07ba972685..7cc78982885a 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1077,6 +1077,7 @@ let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract Gas.consume ctxt (Script.strip_locations_cost code) >>?= fun ctxt -> let code = Script.lazy_expr (Micheline.strip_locations code) in let script = {Script.code; storage} in + let contract = Contract.Originated contract in Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false @@ -1221,7 +1222,7 @@ let apply_internal_manager_operation_content : ~storage_type ~storage ~unparsed_code - ~contract:(Contract.Originated preorigination) + ~contract:preorigination ~delegate ~source ~credit @@ -1432,8 +1433,7 @@ let apply_external_manager_operation_content : so that the script can use it immediately. The address of external originations is generated here. *) Contract.fresh_contract_from_current_nonce ctxt - >>?= fun (ctxt, contract_hash) -> - let contract = Contract.Originated contract_hash in + >>?= fun (ctxt, contract) -> Script.force_decode_in_context ~consume_deserialization_gas ctxt -- GitLab