diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 082901a353bd6eb45ba78c490be62a45e27552f5..de1972620fbef7e35b69a3bb209dd6cf7d5d3d31 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1100,12 +1100,32 @@ let apply_manager_operation_content : ctxt script.code >>?= fun (unparsed_code, ctxt) -> - Script_ir_translator.parse_script - ctxt - ~legacy:false - ~allow_forged_in_storage:internal - script - >>=? fun (Ex_script parsed_script, ctxt) -> + let parse_script ctxt = + Script_ir_translator.parse_script + ctxt + ~legacy:false + ~allow_forged_in_storage:internal + script + in + (* The preorigination field is only used to early return the address of an + originated contract in Michelson. It cannot come from the outside. *) + (match preorigination with + | Some contract -> ( + assert internal ; + (* Try to look up the script from the cache. It may have been stored + there when traversing operations for ticket balance updates. *) + Script_cache.find ctxt contract + >>=? fun (ctxt, _cache_key, cached_script) -> + match cached_script with + | None -> + parse_script ctxt >|=? fun (ex_script, ctxt) -> + (ex_script, contract, ctxt) + | Some (_script, ex_script) -> return (ex_script, contract, ctxt)) + | None -> + parse_script ctxt >>=? fun (ex_script, ctxt) -> + Contract.fresh_contract_from_current_nonce ctxt + >>?= fun (ctxt, contract) -> return (ex_script, contract, ctxt)) + >>=? fun (Ex_script parsed_script, contract, ctxt) -> let views_result = Script_ir_translator.typecheck_views ctxt @@ -1140,15 +1160,6 @@ let apply_manager_operation_content : >>=? fun (storage, ctxt) -> let storage = Script.lazy_expr (Micheline.strip_locations storage) in let script = {script with storage} in - (match preorigination with - | Some contract -> - assert internal ; - (* The preorigination field is only used to early return - the address of an originated contract in Michelson. - It cannot come from the outside. *) - ok (ctxt, contract) - | None -> Contract.fresh_contract_from_current_nonce ctxt) - >>?= fun (ctxt, contract) -> Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out index d10a528548fc24faf759fe07aaa6e811e80bc314..7990d65f34a7d93a2c13ec98238b6d5a6ffb951a 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestOriginateContractFromContract::test_originate_contract_from_contract_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestOriginateContractFromContract::test_originate_contract_from_contract_transfer Node is bootstrapped. -Estimated gas: 3469.422 units (will add 100 for safety) +Estimated gas: 3889.422 units (will add 100 for safety) Estimated storage: 295 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000606 + Fee to the baker: ꜩ0.000648 Expected counter: [EXPECTED_COUNTER] - Gas limit: 3570 + Gas limit: 3990 Storage limit: 315 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000606 - payload fees(the block proposer) ....... +ꜩ0.000606 + [CONTRACT_HASH] ... -ꜩ0.000648 + payload fees(the block proposer) ....... +ꜩ0.000648 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -40,7 +40,7 @@ This sequence of operations was run: [CONTRACT_HASH] Storage size: 38 bytes Paid storage size diff: 38 bytes - Consumed gas: 1405.750 + Consumed gas: 1825.750 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0095 storage fees ........................... +ꜩ0.0095