diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 86a470bbbd3c38d329e78dccef74cff0465d7048..eaab5557d06ba565d0827a426ff6d1b99b84b44c 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -142,88 +142,12 @@ module Ticket_token_map = struct map end -let parse_and_cache_script ctxt ~destination ~get_non_cached_script = - Script_cache.find ctxt destination >>=? fun (ctxt, _cache_key, cached) -> - match cached with - | Some (_script, ex_script) -> return (ex_script, ctxt) - | None -> - get_non_cached_script ctxt >>=? fun (script, ctxt) -> - Script_ir_translator.parse_script - ctxt - ~legacy:true - ~allow_forged_in_storage:true - script - >>=? fun (ex_script, ctxt) -> - (* Add the parsed script to the script-cache in order to avoid having to - re-parse when applying the operation at a later stage. *) - let size, cost = Script_ir_translator.script_size ex_script in - Gas.consume ctxt cost >>?= fun ctxt -> - Script_cache.insert ctxt destination (script, ex_script) size - >>?= fun ctxt -> return (ex_script, ctxt) - -let cast_transaction_parameter (type a ac b bc) ctxt location - (entry_arg_ty : (a, ac) Script_typed_ir.ty) - (parameters_ty : (b, bc) Script_typed_ir.ty) (parameters : b) : - (a * context) tzresult Lwt.t = - Gas_monad.run - ctxt - (Script_ir_translator.ty_eq - ~error_details:(Informative location) - entry_arg_ty - parameters_ty) - >>?= fun (res, ctxt) -> - res >>?= fun Script_ir_translator.Eq -> return ((parameters : a), ctxt) - -let tickets_of_transaction ctxt ~(destination : Contract.t) ~entrypoint - ~location ~parameters_ty ~parameters = - match destination with - | Implicit _ -> return (None, ctxt) - | Originated contract_hash -> - (* TODO: #2653 - Avoid having to load the script from the cache. - This is currently in place to avoid regressions for type-checking - errors. We should be able to remove it. - *) - parse_and_cache_script - ctxt - ~destination:contract_hash - ~get_non_cached_script:(fun ctxt -> - (* Look up the script from the context. *) - Contract.get_script ctxt destination >>=? fun (ctxt, script_opt) -> - match script_opt with - | None -> fail (Failed_to_get_script destination) - | Some script -> return (script, ctxt)) - >>=? fun ( Script_ir_translator.Ex_script - (Script {arg_type; entrypoints; _}), - ctxt ) -> - (* Find the entrypoint type for the given entrypoint. *) - Gas_monad.run - ctxt - (Script_ir_translator.find_entrypoint - ~error_details:(Informative ()) - arg_type - entrypoints - entrypoint) - >>?= fun (res, ctxt) -> - res >>?= fun (Ex_ty_cstr {ty = entry_arg_ty; _}) -> - Ticket_scanner.type_has_tickets ctxt entry_arg_ty - >>?= fun (has_tickets, ctxt) -> - (* Check that the parameter's type matches that of the entry-point, and - cast the parameter if this is the case. *) - cast_transaction_parameter - ctxt - location - entry_arg_ty - parameters_ty - parameters - >>=? fun (parameters, ctxt) -> - Ticket_scanner.tickets_of_value - ~include_lazy:true - ctxt - has_tickets - parameters - >>=? fun (tickets, ctxt) -> - return (Some {destination = Contract destination; tickets}, ctxt) +let tickets_of_transaction ctxt ~destination ~parameters_ty ~parameters = + let destination = Destination.Contract (Originated destination) in + Ticket_scanner.type_has_tickets ctxt parameters_ty + >>?= fun (has_tickets, ctxt) -> + Ticket_scanner.tickets_of_value ~include_lazy:true ctxt has_tickets parameters + >>=? fun (tickets, ctxt) -> return (Some {destination; tickets}, ctxt) (** Extract tickets of an origination operation by scanning the storage. *) let tickets_of_origination ctxt ~preorigination ~storage_type ~storage = @@ -239,23 +163,18 @@ let tickets_of_origination ctxt ~preorigination ~storage_type ~storage = let tickets_of_operation ctxt (Script_typed_ir.Internal_operation {source = _; operation; nonce = _}) = match operation with + | Transaction_to_contract {destination = Implicit _; _} -> return (None, ctxt) | Transaction_to_contract { amount = _; unparsed_parameters = _; - entrypoint; - destination; - location; + entrypoint = _; + destination = Originated destination; + location = _; parameters_ty; parameters; } -> - tickets_of_transaction - ctxt - ~destination - ~entrypoint - ~location - ~parameters_ty - ~parameters + tickets_of_transaction ctxt ~destination ~parameters_ty ~parameters | Transaction_to_tx_rollup {destination; unparsed_parameters = _; parameters_ty; parameters} -> Tx_rollup_parameters.get_deposit_parameters parameters_ty parameters diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out index f6612dd12883f301c33f9e700d82faf2589cc19f..c89dfcbd3781460f2b1f484e7e595ad1e2124c19 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSelfAddressTransfer::test_send_self_address.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestSelfAddressTransfer::test_send_self_address Node is bootstrapped. -Estimated gas: 4693.662 units (will add 100 for safety) +Estimated gas: 4693.447 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -27,7 +27,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 82 bytes - Consumed gas: 3490.572 + Consumed gas: 2575.930 Internal operations: Internal Transaction: Amount: ꜩ0 @@ -37,6 +37,6 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 83 bytes - Consumed gas: 1203.090 + Consumed gas: 2117.517 Injected block at minimal timestamp diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out index ddf5e0f5f28f1021d36b2f78886cb1ac79b0bacf..207c815022dfd0c09a910984da02d45d02788fc5 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_source.out @@ -78,7 +78,7 @@ Injected block at minimal timestamp [CONTRACT_HASH] Node is bootstrapped. -Estimated gas: 3772.624 units (will add 100 for safety) +Estimated gas: 3772.529 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -104,7 +104,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 55 bytes - Consumed gas: 2569.422 + Consumed gas: 2569.327 Internal operations: Internal Transaction: Amount: ꜩ0 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out index 6fbadc4fd870e715236aa4992f7939428ebffcd7..be8806bb9645a811152be545cd8e1ca2869efdf5 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_transfer_tokens.out @@ -143,7 +143,7 @@ Injected block at minimal timestamp [CONTRACT_HASH] Node is bootstrapped. -Estimated gas: 4679.987 units (will add 100 for safety) +Estimated gas: 4679.892 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -169,7 +169,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 66 bytes - Consumed gas: 3477.185 + Consumed gas: 2571.326 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 @@ -181,7 +181,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 38 bytes - Consumed gas: 1202.802 + Consumed gas: 2108.566 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 @@ -191,7 +191,7 @@ Injected block at minimal timestamp [CONTRACT_HASH] Node is bootstrapped. -Estimated gas: 3767.920 units (will add 100 for safety) +Estimated gas: 3767.825 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -217,7 +217,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 66 bytes - Consumed gas: 2565.118 + Consumed gas: 1659.259 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 @@ -229,7 +229,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 38 bytes - Consumed gas: 1202.802 + Consumed gas: 2108.566 Balance updates: [CONTRACT_HASH] ... -ꜩ100 [CONTRACT_HASH] ... +ꜩ100 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out index f29a346d8f8e0e0b48979ec0db7f79ffa694bcb2..69e8f29edb9092913fa11a17ae24d39b21010714 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_add_liquidity Node is bootstrapped. -Estimated gas: 8522.321 units (will add 100 for safety) +Estimated gas: 8521.106 units (will add 100 for safety) Estimated storage: 141 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -14,7 +14,7 @@ This sequence of operations was run: From: [CONTRACT_HASH] Fee to the baker: ꜩ0.001218 Expected counter: [EXPECTED_COUNTER] - Gas limit: 8623 + Gas limit: 8622 Storage limit: 161 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.001218 @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes Paid storage size diff: 3 bytes - Consumed gas: 3783.339 + Consumed gas: 2275.556 Balance updates: [CONTRACT_HASH] ... -ꜩ0.00075 storage fees ........................... +ꜩ0.00075 @@ -75,7 +75,7 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 72007 Storage size: 2048 bytes Paid storage size diff: 70 bytes - Consumed gas: 1673.293 + Consumed gas: 3179.861 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0175 storage fees ........................... +ꜩ0.0175 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out index 3759a9abf71f2f504e2e80dfbfa3f945615dbaf5..207d522bdc3a8a9db4a5ee62f698dbeb0861fb5b 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_remove_liquidity Node is bootstrapped. -Estimated gas: 7520.262 units (will add 100 for safety) +Estimated gas: 7519.047 units (will add 100 for safety) Estimated storage: 67 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.001115 + Fee to the baker: ꜩ0.001114 Expected counter: [EXPECTED_COUNTER] - Gas limit: 7621 + Gas limit: 7620 Storage limit: 87 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001115 - payload fees(the block proposer) ....... +ꜩ0.001115 + [CONTRACT_HASH] ... -ꜩ0.001114 + payload fees(the block proposer) ....... +ꜩ0.001114 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 2278.921 + Consumed gas: 2277.706 Internal operations: Internal Transaction: Amount: ꜩ0 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out index b0f8fa476302c060adfe42419e997b5ea6f0e736..e2738e165f07d004855fba108d310d9078664bd9 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_add_liquidity Node is bootstrapped. -Estimated gas: 8522.321 units (will add 100 for safety) +Estimated gas: 8521.106 units (will add 100 for safety) Estimated storage: 141 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -14,7 +14,7 @@ This sequence of operations was run: From: [CONTRACT_HASH] Fee to the baker: ꜩ0.001218 Expected counter: [EXPECTED_COUNTER] - Gas limit: 8623 + Gas limit: 8622 Storage limit: 161 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.001218 @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes Paid storage size diff: 3 bytes - Consumed gas: 3783.339 + Consumed gas: 2275.556 Balance updates: [CONTRACT_HASH] ... -ꜩ0.00075 storage fees ........................... +ꜩ0.00075 @@ -75,7 +75,7 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 72007 Storage size: 2048 bytes Paid storage size diff: 70 bytes - Consumed gas: 1673.293 + Consumed gas: 3179.861 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0175 storage fees ........................... +ꜩ0.0175 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out index 58d78a9381d496351cc320d6d8b048dd9132d8be..9adda170f74d7f638e11cc3a8db0f4cfc7123015 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_buy_tok Node is bootstrapped. -Estimated gas: 5115.243 units (will add 100 for safety) +Estimated gas: 5114.558 units (will add 100 for safety) Estimated storage: 326 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -14,7 +14,7 @@ This sequence of operations was run: From: [CONTRACT_HASH] Fee to the baker: ꜩ0.000869 Expected counter: [EXPECTED_COUNTER] - Gas limit: 5216 + Gas limit: 5215 Storage limit: 346 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.000869 @@ -34,7 +34,7 @@ This sequence of operations was run: 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4634 bytes Paid storage size diff: 1 bytes - Consumed gas: 1747.265 + Consumed gas: 1746.580 Balance updates: [CONTRACT_HASH] ... -ꜩ0.00025 storage fees ........................... +ꜩ0.00025 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out index da9a8b0e15ef8d3dd437ac25388759b7344d0bdb..2771ad0c0efdbd33694ccdf7673bdf2ce879251e 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_sell_tok Node is bootstrapped. -Estimated gas: 7014.174 units (will add 100 for safety) +Estimated gas: 7013.489 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -14,7 +14,7 @@ This sequence of operations was run: From: [CONTRACT_HASH] Fee to the baker: ꜩ0.001057 Expected counter: [EXPECTED_COUNTER] - Gas limit: 7115 + Gas limit: 7114 Storage limit: 0 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.001057 @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01e927f00ef734dfc85919635e9afc9166c83ef9fc00 ; 0x0115eb0104481a6d7921160bc982c5e0a561cd8a3a00 } Storage size: 4633 bytes - Consumed gas: 1748.449 + Consumed gas: 1747.764 Internal operations: Internal Transaction: Amount: ꜩ0