From 7e0c7aa84cd4dfbaa912d93f5adf1fdbbfb4f23b Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 6 May 2022 11:46:48 +0200 Subject: [PATCH 1/6] Proto/Cache: make insert work on originated contracts only --- src/proto_alpha/lib_protocol/script_cache.ml | 1 + src/proto_alpha/lib_protocol/script_cache.mli | 5 +++-- src/proto_alpha/lib_protocol/ticket_operations_diff.ml | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml index 74ecd7973811..00761fb38f9b 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml +++ b/src/proto_alpha/lib_protocol/script_cache.ml @@ -109,5 +109,6 @@ let size = Cache.size let size_limit = Cache.size_limit let insert ctxt addr updated_script approx_size = + let addr = Contract.Originated addr in let identifier = identifier_of_contract addr in Cache.update ctxt identifier (Some (updated_script, approx_size)) diff --git a/src/proto_alpha/lib_protocol/script_cache.mli b/src/proto_alpha/lib_protocol/script_cache.mli index 09ebdb26b17d..495a6e741302 100644 --- a/src/proto_alpha/lib_protocol/script_cache.mli +++ b/src/proto_alpha/lib_protocol/script_cache.mli @@ -81,5 +81,6 @@ val size : context -> int val size_limit : context -> int (** [insert] is a variant of [update] which identifies the contract to update - by its address (of type [Contract.t]) instead of its cache identifier. *) -val insert : context -> Contract.t -> cached_contract -> int -> context tzresult + by its address (of type [Contract_hash.t]) instead of its cache identifier. *) +val insert : + context -> Contract_hash.t -> cached_contract -> int -> context tzresult diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 22a4adde45df..79dcfa954715 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -143,7 +143,8 @@ module Ticket_token_map = struct end let parse_and_cache_script ctxt ~destination ~get_non_cached_script = - Script_cache.find ctxt destination >>=? fun (ctxt, _cache_key, cached) -> + Script_cache.find ctxt (Contract.Originated destination) + >>=? fun (ctxt, _cache_key, cached) -> match cached with | Some (_script, ex_script) -> return (ex_script, ctxt) | None -> @@ -178,7 +179,7 @@ let tickets_of_transaction ctxt ~(destination : Contract.t) ~entrypoint ~location ~parameters_ty ~parameters = match destination with | Implicit _ -> return (None, ctxt) - | Originated _ -> + | 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 @@ -186,7 +187,7 @@ let tickets_of_transaction ctxt ~(destination : Contract.t) ~entrypoint *) parse_and_cache_script ctxt - ~destination + ~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) -> -- GitLab From 1c3f0208d6f39d9e88bb3b41b7bafa4c99b2c9b4 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 16:12:25 +0200 Subject: [PATCH 2/6] Proto/Cache: make find work on originated contracts only --- .../lib_benchmarks_proto/cache_benchmarks.ml | 8 +++---- src/proto_alpha/lib_protocol/apply.ml | 6 ++--- src/proto_alpha/lib_protocol/script_cache.ml | 1 + src/proto_alpha/lib_protocol/script_cache.mli | 2 +- .../michelson/test_script_cache.ml | 23 ++++++++++--------- .../lib_protocol/ticket_operations_diff.ml | 3 +-- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml index 875d80b6897a..e6cdd5e17d3b 100644 --- a/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml @@ -95,14 +95,12 @@ module Cache_shared_config = struct end (* We can't produce a Script_cache.identifier without calling [Script_cache.find]. *) -let identifier_of_contract (c : Alpha_context.Contract.t) : Cache.identifier = +let identifier_of_contract (c : Contract_hash.t) : Cache.identifier = let _, id, _ = Cache.find throwaway_context c |> assert_ok_lwt in id -let contract_of_int i : Alpha_context.Contract.t = - Alpha_context.Contract.of_b58check - Contract_hash.(to_b58check (hash_string [string_of_int i])) - |> assert_ok +let contract_of_int i : Contract_hash.t = + Contract_hash.(of_b58check_exn (to_b58check (hash_string [string_of_int i]))) let identifier_of_int i = identifier_of_contract @@ contract_of_int i diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 42694c1fbcf1..50c8602820da 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -938,7 +938,7 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount let apply_transaction ~ctxt ~parameter ~source ~(contract : Contract.t) ~amount ~entrypoint ~before_operation ~payer ~chain_id ~mode ~internal = match contract with - | Originated _ -> ( + | Originated contract_hash -> ( (* Since the contract is originated, nothing will be allocated or this transfer of tokens will fail. Calls to non-existing contracts are detected by [Script_cache.find] @@ -947,7 +947,7 @@ let apply_transaction ~ctxt ~parameter ~source ~(contract : Contract.t) ~amount *) Token.transfer ctxt (`Contract source) (`Contract contract) amount >>=? fun (ctxt, balance_updates) -> - Script_cache.find ctxt contract >>=? fun (ctxt, cache_key, script) -> + Script_cache.find ctxt contract_hash >>=? fun (ctxt, cache_key, script) -> match script with | None -> fail (Contract.Non_existing_contract contract) | Some (script, script_ir) -> @@ -3131,7 +3131,7 @@ let apply_liquidity_baking_subsidy ctxt ~toggle_vote = (`Contract liquidity_baking_cpmm_contract) liquidity_baking_subsidy >>=? fun (ctxt, balance_updates) -> - Script_cache.find ctxt liquidity_baking_cpmm_contract + Script_cache.find ctxt liquidity_baking_cpmm_contract_hash >>=? fun (ctxt, cache_key, script) -> match script with | None -> fail (Script_tc_errors.No_such_entrypoint Entrypoint.default) diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml index 00761fb38f9b..539833f183c4 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml +++ b/src/proto_alpha/lib_protocol/script_cache.ml @@ -79,6 +79,7 @@ end module Cache = (val Cache.register_exn (module Client)) let find ctxt addr = + let addr = Contract.Originated addr in let identifier = identifier_of_contract addr in Cache.find ctxt identifier >>=? function | Some (unparsed_script, ex_script) -> diff --git a/src/proto_alpha/lib_protocol/script_cache.mli b/src/proto_alpha/lib_protocol/script_cache.mli index 495a6e741302..e69991a58388 100644 --- a/src/proto_alpha/lib_protocol/script_cache.mli +++ b/src/proto_alpha/lib_protocol/script_cache.mli @@ -54,7 +54,7 @@ type cached_contract = Script.t * Script_ir_translator.ex_script and [Script_ir_translator.parse_script]. *) val find : context -> - Contract.t -> + Contract_hash.t -> (context * identifier * cached_contract option) tzresult Lwt.t (** [update ctxt identifier unparsed_script ir_script size] refreshes the diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml index a02bda8b2508..0122eb9e4111 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml @@ -49,9 +49,7 @@ let err x = Exn (Script_cache_test_error x) let liquidity_baking_contract_size = 267304 let liquidity_baking_contract = - Contract.of_b58check "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5" |> function - | Ok x -> x - | _ -> assert false + Contract_hash.of_b58check_exn "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5" let make_block block f = Incremental.begin_construction block >>=? fun incr -> @@ -96,7 +94,7 @@ let add_some_contracts k src block baker = >>=? fun (liquidity_baking_contract_id, block) -> List.fold_left_es (fun (rev_contracts, block) _ -> - originate_contract "contracts/int-store.tz" "31" src block baker + originate_contract_hash "contracts/int-store.tz" "31" src block baker >>=? fun (addr, block) -> Block.bake block >>=? fun block -> make_block block @@ fun ctxt -> @@ -143,7 +141,7 @@ let test_size_of_liquidity_baking_contract () = let test_size_of_int_store_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract "contracts/int-store.tz" "31" src block baker + originate_contract_hash "contracts/int-store.tz" "31" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> Script_cache.find ctxt addr >|= Environment.wrap_tzresult @@ -160,7 +158,7 @@ let test_size_of_int_store_contract () = *) let test_find_correctly_looks_up () = init () >>=? fun (block, baker, src, _) -> - originate_contract "contracts/sapling_contract.tz" "{ }" src block baker + originate_contract_hash "contracts/sapling_contract.tz" "{ }" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> (* @@ -168,7 +166,8 @@ let test_find_correctly_looks_up () = *) Script_cache.find ctxt addr >|= Environment.wrap_tzresult >>=? fun (_, _, result) -> - Contract.get_script ctxt addr >|= Environment.wrap_tzresult + Contract.get_script ctxt (Contract.Originated addr) + >|= Environment.wrap_tzresult >>=? fun (ctxt, script) -> (match (result, script) with | None, _ -> ok false @@ -185,7 +184,6 @@ let test_find_correctly_looks_up () = *) >>=? fun () -> let addr = Contract_helpers.fake_KT1 in - let addr = Contract.Originated addr in Script_cache.find ctxt addr >|= Environment.wrap_tzresult >>=? fun (_, _, cached_contract) -> fail_unless @@ -200,7 +198,7 @@ let test_find_correctly_looks_up () = *) let test_update_modifies_cached_contract () = init () >>=? fun (block, baker, src, _) -> - originate_contract "contracts/int-store.tz" "36" src block baker + originate_contract_hash "contracts/int-store.tz" "36" src block baker >>=? fun (addr, block) -> ( make_block block @! fun ctxt -> find ctxt addr >>=? fun (ctxt, identifier, script, Ex_script (Script ir)) -> @@ -241,6 +239,7 @@ let test_entries_returns_the_list_in_correct_order () = ( make_block block @! fun ctxt -> Script_cache.entries ctxt |> Environment.wrap_tzresult >>?= fun entries -> let cached_contracts = fst (List.split entries) in + let addrs = List.map (fun c -> Contract.Originated c) addrs in fail_unless (addrs = cached_contracts) (err "entries must return cached contracts in order") ) @@ -260,6 +259,7 @@ let test_contract_rank_is_lru_rank () = let rec check_rank k = function | [] -> return () | addr :: addrs -> ( + let addr = Contract.Originated addr in match Script_cache.contract_rank ctxt addr with | None -> fail (err "Contract rank should find a cached contract") | Some rank -> @@ -367,7 +367,8 @@ let test_entries_shows_lru () = (ncontracts / 2))) | (contract, size) :: rev_entries, (_, contract') :: rev_contracts -> fail_unless - (size = new_size || contract = liquidity_baking_contract) + (size = new_size + || contract = Contract.Originated liquidity_baking_contract) (err (Printf.sprintf "A contract in the cache has not the right size, expecting \ @@ -376,7 +377,7 @@ let test_entries_shows_lru () = size)) >>=? fun () -> fail_unless - (contract = contract') + (contract = Contract.Originated contract') (err (Printf.sprintf "entries do not return cached contracts in right order")) diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 79dcfa954715..737deb72c42a 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -143,8 +143,7 @@ module Ticket_token_map = struct end let parse_and_cache_script ctxt ~destination ~get_non_cached_script = - Script_cache.find ctxt (Contract.Originated destination) - >>=? fun (ctxt, _cache_key, cached) -> + Script_cache.find ctxt destination >>=? fun (ctxt, _cache_key, cached) -> match cached with | Some (_script, ex_script) -> return (ex_script, ctxt) | None -> -- GitLab From 26909b57f7027214076a4d3e9fb0f8f84fc00922 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 16:12:25 +0200 Subject: [PATCH 3/6] Proto/Cache: make contract_rank work on originated contracts only --- src/proto_alpha/lib_client/client_proto_context.mli | 2 +- .../lib_client_commands/client_proto_context_commands.ml | 6 +----- src/proto_alpha/lib_protocol/alpha_services.ml | 2 +- src/proto_alpha/lib_protocol/alpha_services.mli | 2 +- src/proto_alpha/lib_protocol/script_cache.ml | 1 + src/proto_alpha/lib_protocol/script_cache.mli | 2 +- .../test/integration/michelson/test_script_cache.ml | 1 - 7 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index dac109654d59..62d3b40991f1 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -405,7 +405,7 @@ val contract_rank : #Protocol_client_context.full -> chain:Shell_services.chain -> block:Shell_services.block -> - Contract.t -> + Contract_hash.t -> int option tzresult Lwt.t val contract_cache_size : diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 7496e2e7c998..4e898335817a 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -213,15 +213,11 @@ let commands_ro () = @@ OriginatedContractAlias.destination_param ~name:"src" ~desc:"contract" @@ stop) (fun () contract (cctxt : Protocol_client_context.full) -> - let contract = Contract.Originated contract in contract_rank cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? fun rank -> match rank with | None -> - cctxt#error - "Invalid contract: %a" - Alpha_context.Contract.pp - contract + cctxt#error "Invalid contract: %a" Contract_hash.pp contract >>= fun () -> return_unit | Some rank -> cctxt#message "%d" rank >>= fun () -> return_unit); command diff --git a/src/proto_alpha/lib_protocol/alpha_services.ml b/src/proto_alpha/lib_protocol/alpha_services.ml index 6c8161d4cae1..6476afc11cf1 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.ml +++ b/src/proto_alpha/lib_protocol/alpha_services.ml @@ -222,7 +222,7 @@ module Cache = struct "Return the number of cached contracts older than the provided \ contract" ~query:RPC_query.empty - ~input:Alpha_context.Contract.encoding + ~input:Alpha_context.Contract.originated_encoding ~output:Data_encoding.(option int31) RPC_path.(custom_root / "context" / "cache" / "contracts" / "rank") end diff --git a/src/proto_alpha/lib_protocol/alpha_services.mli b/src/proto_alpha/lib_protocol/alpha_services.mli index 25a22c348773..5c0a0eebf50d 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.mli +++ b/src/proto_alpha/lib_protocol/alpha_services.mli @@ -81,7 +81,7 @@ module Cache : sig val contract_rank : 'a #RPC_context.simple -> 'a -> - Alpha_context.Contract.t -> + Contract_hash.t -> int option shell_tzresult Lwt.t end diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml index 539833f183c4..6e03ad479dab 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml +++ b/src/proto_alpha/lib_protocol/script_cache.ml @@ -103,6 +103,7 @@ let entries ctxt = contract_of_identifier identifier >|? fun contract -> (contract, age) let contract_rank ctxt addr = + let addr = Contract.Originated addr in Cache.identifier_rank ctxt (identifier_of_contract addr) let size = Cache.size diff --git a/src/proto_alpha/lib_protocol/script_cache.mli b/src/proto_alpha/lib_protocol/script_cache.mli index e69991a58388..6297246411d5 100644 --- a/src/proto_alpha/lib_protocol/script_cache.mli +++ b/src/proto_alpha/lib_protocol/script_cache.mli @@ -71,7 +71,7 @@ val entries : context -> (Contract.t * int) list tzresult older than [contract] in the cache of [ctxt]. This function returns [None] if [contract] does not exist in the cache of [ctxt]. *) -val contract_rank : context -> Contract.t -> int option +val contract_rank : context -> Contract_hash.t -> int option (** [size ctxt] is an overapproximation of the cache size in memory (in bytes). *) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml index 0122eb9e4111..158c71fb1d92 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml @@ -259,7 +259,6 @@ let test_contract_rank_is_lru_rank () = let rec check_rank k = function | [] -> return () | addr :: addrs -> ( - let addr = Contract.Originated addr in match Script_cache.contract_rank ctxt addr with | None -> fail (err "Contract rank should find a cached contract") | Some rank -> -- GitLab From b0370c9f98ef3b80ec53141eebba2553a3c416e4 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 6 May 2022 12:03:50 +0200 Subject: [PATCH 4/6] Proto/Cache: make identifier_of_contract work on originated contracts only --- src/proto_alpha/lib_protocol/script_cache.ml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml index 6e03ad479dab..b086cbe25e80 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml +++ b/src/proto_alpha/lib_protocol/script_cache.ml @@ -27,7 +27,7 @@ open Alpha_context type identifier = string -let identifier_of_contract addr = Contract.to_b58check addr +let identifier_of_contract addr = Contract_hash.to_b58check addr let contract_of_identifier identifier = Contract.of_b58check identifier @@ -79,12 +79,12 @@ end module Cache = (val Cache.register_exn (module Client)) let find ctxt addr = - let addr = Contract.Originated addr in let identifier = identifier_of_contract addr in Cache.find ctxt identifier >>=? function | Some (unparsed_script, ex_script) -> return (ctxt, identifier, Some (unparsed_script, ex_script)) | None -> ( + let addr = Contract.Originated addr in load_and_elaborate ctxt addr >>=? function | ctxt, None -> return (ctxt, identifier, None) | ctxt, Some (unparsed_script, script_ir, size) -> @@ -103,7 +103,6 @@ let entries ctxt = contract_of_identifier identifier >|? fun contract -> (contract, age) let contract_rank ctxt addr = - let addr = Contract.Originated addr in Cache.identifier_rank ctxt (identifier_of_contract addr) let size = Cache.size @@ -111,6 +110,5 @@ let size = Cache.size let size_limit = Cache.size_limit let insert ctxt addr updated_script approx_size = - let addr = Contract.Originated addr in let identifier = identifier_of_contract addr in Cache.update ctxt identifier (Some (updated_script, approx_size)) -- GitLab From 8e165b38c2cadcbb8773139627727a451c998379 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 16:12:25 +0200 Subject: [PATCH 5/6] Proto/Cache: make contract_of_identifier return a contract hash --- src/proto_alpha/lib_protocol/script_cache.ml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml index b086cbe25e80..d7f981bf52bf 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml +++ b/src/proto_alpha/lib_protocol/script_cache.ml @@ -29,11 +29,15 @@ type identifier = string let identifier_of_contract addr = Contract_hash.to_b58check addr -let contract_of_identifier identifier = Contract.of_b58check identifier +let contract_of_identifier identifier = + match Contract_hash.of_b58check_opt identifier with + | Some addr -> Ok addr + | None -> error (Contract_repr.Invalid_contract_notation identifier) type cached_contract = Script.t * Script_ir_translator.ex_script let load_and_elaborate ctxt addr = + let addr = Contract.Originated addr in Contract.get_script ctxt addr >>=? fun (ctxt, script) -> match script with | None -> return (ctxt, None) @@ -84,7 +88,6 @@ let find ctxt addr = | Some (unparsed_script, ex_script) -> return (ctxt, identifier, Some (unparsed_script, ex_script)) | None -> ( - let addr = Contract.Originated addr in load_and_elaborate ctxt addr >>=? function | ctxt, None -> return (ctxt, identifier, None) | ctxt, Some (unparsed_script, script_ir, size) -> @@ -100,7 +103,9 @@ let update ctxt identifier updated_script approx_size = let entries ctxt = Cache.list_identifiers ctxt |> List.map_e @@ fun (identifier, age) -> - contract_of_identifier identifier >|? fun contract -> (contract, age) + contract_of_identifier identifier >|? fun contract -> + let contract = Contract.Originated contract in + (contract, age) let contract_rank ctxt addr = Cache.identifier_rank ctxt (identifier_of_contract addr) -- GitLab From 78ede0faf8c2362ef45ea3d2d6ae6b9ef4913c32 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 16:12:25 +0200 Subject: [PATCH 6/6] Proto/Cache: entries return contract hashes --- src/proto_alpha/lib_client/client_proto_context.mli | 2 +- .../lib_client_commands/client_proto_context_commands.ml | 3 +-- src/proto_alpha/lib_protocol/alpha_services.ml | 3 +-- src/proto_alpha/lib_protocol/alpha_services.mli | 2 +- src/proto_alpha/lib_protocol/script_cache.ml | 4 +--- src/proto_alpha/lib_protocol/script_cache.mli | 2 +- .../test/integration/michelson/test_script_cache.ml | 6 ++---- 7 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 62d3b40991f1..abcfb614768d 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -399,7 +399,7 @@ val cached_contracts : #Protocol_client_context.full -> chain:Shell_services.chain -> block:Shell_services.block -> - (Contract.t * int) list tzresult Lwt.t + (Contract_hash.t * int) list tzresult Lwt.t val contract_rank : #Protocol_client_context.full -> diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 4e898335817a..36a849a75bd6 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -201,8 +201,7 @@ let commands_ro () = cached_contracts cctxt ~chain:cctxt#chain ~block:cctxt#block >>=? fun keys -> List.iter_s - (fun (key, size) -> - cctxt#message "%a %d" Alpha_context.Contract.pp key size) + (fun (key, size) -> cctxt#message "%a %d" Contract_hash.pp key size) keys >>= fun () -> return_unit); command diff --git a/src/proto_alpha/lib_protocol/alpha_services.ml b/src/proto_alpha/lib_protocol/alpha_services.ml index 6476afc11cf1..ad6eccf851a5 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.ml +++ b/src/proto_alpha/lib_protocol/alpha_services.ml @@ -197,8 +197,7 @@ module Cache = struct RPC_service.get_service ~description:"Return the list of cached contracts" ~query:RPC_query.empty - ~output: - Data_encoding.(list @@ tup2 Alpha_context.Contract.encoding int31) + ~output:Data_encoding.(list @@ tup2 Contract_hash.encoding int31) RPC_path.(custom_root / "context" / "cache" / "contracts" / "all") let contract_cache_size = diff --git a/src/proto_alpha/lib_protocol/alpha_services.mli b/src/proto_alpha/lib_protocol/alpha_services.mli index 5c0a0eebf50d..5bfc4054c68b 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.mli +++ b/src/proto_alpha/lib_protocol/alpha_services.mli @@ -70,7 +70,7 @@ module Cache : sig val cached_contracts : 'a #RPC_context.simple -> 'a -> - (Alpha_context.Contract.t * int) list shell_tzresult Lwt.t + (Contract_hash.t * int) list shell_tzresult Lwt.t val contract_cache_size : 'a #RPC_context.simple -> 'a -> int shell_tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml index d7f981bf52bf..6750a99d2061 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml +++ b/src/proto_alpha/lib_protocol/script_cache.ml @@ -103,9 +103,7 @@ let update ctxt identifier updated_script approx_size = let entries ctxt = Cache.list_identifiers ctxt |> List.map_e @@ fun (identifier, age) -> - contract_of_identifier identifier >|? fun contract -> - let contract = Contract.Originated contract in - (contract, age) + contract_of_identifier identifier >|? fun contract -> (contract, age) let contract_rank ctxt addr = Cache.identifier_rank ctxt (identifier_of_contract addr) diff --git a/src/proto_alpha/lib_protocol/script_cache.mli b/src/proto_alpha/lib_protocol/script_cache.mli index 6297246411d5..03a856926c38 100644 --- a/src/proto_alpha/lib_protocol/script_cache.mli +++ b/src/proto_alpha/lib_protocol/script_cache.mli @@ -65,7 +65,7 @@ val update : context -> identifier -> cached_contract -> int -> context tzresult (** [entries ctxt] returns the contracts in the cache as well as their respective size. The list is sorted by date of last modification: the least recently updated entry comes first. *) -val entries : context -> (Contract.t * int) list tzresult +val entries : context -> (Contract_hash.t * int) list tzresult (** [contract_rank ctxt contract] returns the number of contracts older than [contract] in the cache of [ctxt]. This function diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml index 158c71fb1d92..13962d62487f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_script_cache.ml @@ -239,7 +239,6 @@ let test_entries_returns_the_list_in_correct_order () = ( make_block block @! fun ctxt -> Script_cache.entries ctxt |> Environment.wrap_tzresult >>?= fun entries -> let cached_contracts = fst (List.split entries) in - let addrs = List.map (fun c -> Contract.Originated c) addrs in fail_unless (addrs = cached_contracts) (err "entries must return cached contracts in order") ) @@ -366,8 +365,7 @@ let test_entries_shows_lru () = (ncontracts / 2))) | (contract, size) :: rev_entries, (_, contract') :: rev_contracts -> fail_unless - (size = new_size - || contract = Contract.Originated liquidity_baking_contract) + (size = new_size || contract = liquidity_baking_contract) (err (Printf.sprintf "A contract in the cache has not the right size, expecting \ @@ -376,7 +374,7 @@ let test_entries_shows_lru () = size)) >>=? fun () -> fail_unless - (contract = Contract.Originated contract') + (contract = contract') (err (Printf.sprintf "entries do not return cached contracts in right order")) -- GitLab