From 571db19aa73c39518a5396001dbdd28aed65dd7d Mon Sep 17 00:00:00 2001 From: mbourgoin Date: Fri, 18 Oct 2024 12:00:03 +0200 Subject: [PATCH 1/2] manifest/context: remove access to context sublibs --- brassaia/test/dune | 2 +- devtools/testnet_experiment_tools/dune | 4 +- manifest/product_octez.ml | 206 +++++++++--------- opam/tezos_internal_brassaia_tests.opam | 1 + src/lib_node_config/dune | 4 +- .../context_ops/context_ops.ml | 4 + .../context_ops/context_ops.mli | 11 + .../test_shell_context/dune | 2 +- src/lib_protocol_updater/dune | 4 +- src/lib_shell/test/dune | 4 - src/lib_shell/test/test_prevalidation.ml | 7 +- src/lib_store/unix/dune | 4 +- src/lib_store/unix/snapshots.ml | 43 ++-- .../lib_delegate/abstract_context_index.ml | 6 +- .../lib_delegate/abstract_context_index.mli | 2 +- .../lib_delegate/baking_simulator.ml | 2 +- src/proto_020_PsParisC/lib_delegate/dune | 4 - src/proto_021_PsQuebec/lib_delegate/dune | 2 - src/proto_alpha/lib_delegate/dune | 2 - 19 files changed, 155 insertions(+), 159 deletions(-) diff --git a/brassaia/test/dune b/brassaia/test/dune index b326cd0db01f..88240e300349 100644 --- a/brassaia/test/dune +++ b/brassaia/test/dune @@ -10,7 +10,7 @@ octez-libs.base octez-libs.base.unix octez-libs.brassaia_test_helpers - octez-libs.tezos-context-brassaia.disk + octez-shell-libs.context-ops octez-libs.stdlib-unix octez-libs.test-helpers tezt) diff --git a/devtools/testnet_experiment_tools/dune b/devtools/testnet_experiment_tools/dune index 6ea052d55700..be336d5bd3ac 100644 --- a/devtools/testnet_experiment_tools/dune +++ b/devtools/testnet_experiment_tools/dune @@ -39,7 +39,7 @@ octez-shell-libs.client-base-unix octez-shell-libs.store octez-shell-libs.store.shared - octez-libs.tezos-context + octez-shell-libs.context-ops octez-protocol-020-PsParisC-libs.baking octez-protocol-020-PsParisC-libs.client octez-protocol-020-PsParisC-libs.client.commands @@ -62,7 +62,7 @@ -open Tezos_client_base_unix -open Tezos_store -open Tezos_store_shared - -open Tezos_context) + -open Tezos_context_ops) (modules sigs tool_020_PsParisC tool_021_PsQuebec tool_alpha)) (executable diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index b99bf8215619..c9bcb3bc8ee1 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -2717,29 +2717,6 @@ let octez_context_disk = ] ~conflicts:[Conflicts.checkseum] -(* Should not be used directly in most cases, use context_ops abstraction instead *) -let octez_context_brassaia_disk = - octez_lib - "tezos-context-brassaia.disk" - ~path:"src/lib_context_brassaia/disk" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - bigstringaf; - fmt; - brassaia; - brassaia_pack; - brassaia_pack_unix; - logs_fmt; - octez_stdlib_unix |> open_; - octez_stdlib |> open_; - octez_context_sigs; - octez_context_brassaia_helpers; - octez_context_brassaia_encoding; - octez_context_brassaia_memory |> open_; - ] - ~conflicts:[Conflicts.checkseum] - let _tree_encoding_tests = tezt ["test_proofs"; "test_encoding"] @@ -2759,20 +2736,6 @@ let _tree_encoding_tests = alcotezt; ] -let octez_context = - octez_lib - "tezos-context" - ~path:"src/lib_context" - ~synopsis:"On-disk context abstraction for [octez-node]" - ~deps:[octez_context_disk; octez_context_memory] - -let octez_context_brassaia = - octez_lib - "tezos-context-brassaia" - ~path:"src/lib_context_brassaia" - ~synopsis:"On-disk context abstraction for [octez-node] (brassaia)" - ~deps:[octez_context_brassaia_disk; octez_context_brassaia_memory] - let _octez_context_tests = tezt ["test_context"; "test_merkle_proof"; "tezt_main"] @@ -2825,23 +2788,6 @@ let _irmin_tests = tezt_lib |> open_ |> open_ ~m:"Base"; ] -let _brassaia_tests = - tezt - ["tezt_brassaia"; "test_lib_brassaia_store"; "test_utils"] - ~path:"brassaia/test" - ~opam:"tezos_internal_brassaia_tests" - ~synopsis:"Tezos internal brassaia tests" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - octez_base_unix; - brassaia_test_helpers; - octez_context_brassaia_disk; - octez_stdlib_unix |> open_; - octez_test_helpers |> open_; - tezt_lib |> open_ |> open_ ~m:"Base"; - ] - let _irmin_data_tests = tezt ["test"; "import"; "test_fixed_size_string_set"] @@ -3262,48 +3208,6 @@ let octez_protocol_environment = octez_event_logging; ] -(* in general this library should not be used directly, context_ops should be - used instead *) -let octez_shell_context = - octez_shell_lib - "shell-context" - ~internal_name:"tezos_shell_context" - ~path:"src/lib_protocol_environment/shell_context" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - octez_protocol_environment; - octez_context; - ] - -let octez_brassaia_context = - octez_shell_lib - "brassaia-context" - ~internal_name:"tezos_brassaia_context" - ~path:"src/lib_protocol_environment/brassaia_context" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - octez_protocol_environment; - octez_context_brassaia; - ] - -let octez_duo_context_lib = - let (PPX {preprocess; preprocessor_deps}) = ppx_profiler in - octez_shell_lib - "duo-context-lib" - ~internal_name:"tezos_duo_context_lib" - ~path:"src/lib_protocol_environment/duo_context_lib" - ~preprocess - ~preprocessor_deps - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - octez_protocol_environment; - octez_context_brassaia; - octez_context; - ] - let _octez_protocol_environment_tests = tezt [ @@ -3327,6 +3231,85 @@ let _octez_protocol_environment_tests = ] let octez_context_ops = + let octez_context_brassaia_disk = + octez_lib + "tezos-context-brassaia.disk" + ~path:"src/lib_context_brassaia/disk" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + bigstringaf; + fmt; + brassaia; + brassaia_pack; + brassaia_pack_unix; + logs_fmt; + octez_stdlib_unix |> open_; + octez_stdlib |> open_; + octez_context_sigs; + octez_context_brassaia_helpers; + octez_context_brassaia_encoding; + octez_context_brassaia_memory |> open_; + ] + ~conflicts:[Conflicts.checkseum] + in + let octez_context_brassaia = + (* Should not be used directly in most cases, use context_ops abstraction instead *) + octez_lib + "tezos-context-brassaia" + ~path:"src/lib_context_brassaia" + ~synopsis:"On-disk context abstraction for [octez-node] (brassaia)" + ~deps:[octez_context_brassaia_disk; octez_context_brassaia_memory] + in + let octez_brassaia_context = + octez_shell_lib + "brassaia-context" + ~internal_name:"tezos_brassaia_context" + ~path:"src/lib_protocol_environment/brassaia_context" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_protocol_environment; + octez_context_brassaia; + ] + in + let octez_context = + octez_lib + "tezos-context" + ~path:"src/lib_context" + ~synopsis:"On-disk context abstraction for [octez-node]" + ~deps:[octez_context_disk; octez_context_memory] + in + (* in general this library should not be used directly, context_ops should be + used instead *) + let octez_shell_context = + octez_shell_lib + "shell-context" + ~internal_name:"tezos_shell_context" + ~path:"src/lib_protocol_environment/shell_context" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_protocol_environment; + octez_context; + ] + in + let octez_duo_context_lib = + let (PPX {preprocess; preprocessor_deps}) = ppx_profiler in + octez_shell_lib + "duo-context-lib" + ~internal_name:"tezos_duo_context_lib" + ~path:"src/lib_protocol_environment/duo_context_lib" + ~preprocess + ~preprocessor_deps + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_protocol_environment; + octez_context_brassaia; + octez_context; + ] + in let (PPX {preprocess; preprocessor_deps}) = ppx_profiler in octez_shell_lib "context-ops" @@ -3347,6 +3330,23 @@ let octez_context_ops = octez_duo_context_lib |> open_; ] +let _brassaia_tests = + tezt + ["tezt_brassaia"; "test_lib_brassaia_store"; "test_utils"] + ~path:"brassaia/test" + ~opam:"tezos_internal_brassaia_tests" + ~synopsis:"Tezos internal brassaia tests" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_base_unix; + brassaia_test_helpers; + octez_context_ops; + octez_stdlib_unix |> open_; + octez_test_helpers |> open_; + tezt_lib |> open_ |> open_ ~m:"Base"; + ] + let _octez_protocol_shell_context_tests = tezt ["test_proxy_context"] @@ -3354,7 +3354,7 @@ let _octez_protocol_shell_context_tests = ~opam:"octez-shell-libs" ~deps: [ - octez_shell_context; + octez_context_ops; alcotezt; octez_test_helpers |> open_; octez_base |> open_ ~m:"TzPervasives"; @@ -3523,7 +3523,7 @@ let octez_protocol_updater = octez_protocol_environment; octez_protocol_compiler_registerer; octez_protocol_compiler_native; - octez_context |> open_; + octez_context_ops |> open_; lwt_exit; dynlink; ] @@ -3649,7 +3649,7 @@ let octez_store_unix_snapshots = octez_stdlib_unix |> open_; octez_crypto |> open_; octez_shell_services |> open_; - octez_context |> open_; + octez_context_ops |> open_; octez_validation |> open_; octez_store_shared |> open_; octez_store_unix |> open_; @@ -4735,7 +4735,7 @@ let octez_node_config = octez_shell_services |> open_; octez_rpc_http |> open_; octez_rpc_http_server |> open_; - octez_context |> open_; + octez_context_ops |> open_; octez_store |> open_; octez_validation |> open_; ] @@ -6566,8 +6566,6 @@ let hash = Protocol.hash octez_client_commands |> open_; octez_stdlib |> open_; octez_stdlib_unix |> open_; - octez_shell_context |> if_ N.(number <= 020) |> open_; - octez_context |> open_; octez_context_memory |> if_ (N.(number >= 012) && N.(number <= 019)); octez_rpc_http_client_unix |> if_ N.(number >= 011); octez_rpc_http_client |> if_ N.(number >= 011) |> open_; @@ -7383,9 +7381,7 @@ let _octez_shell_tests = octez_base_test_helpers |> open_; octez_store |> open_; octez_store_shared |> open_; - octez_context |> open_; octez_context_ops |> open_; - octez_shell_context |> open_; octez_protocol_updater |> open_; octez_p2p |> open_; octez_p2p_services |> open_; @@ -7675,7 +7671,7 @@ let simulation_scenario_lib = octez_client_base_unix |> open_; octez_store |> open_; octez_store_shared |> open_; - octez_context |> open_; + octez_context_ops |> open_; ] @ List.flatten proto_deps) ~modules:("sigs" :: proto_tools) diff --git a/opam/tezos_internal_brassaia_tests.opam b/opam/tezos_internal_brassaia_tests.opam index 1920404dbcaf..fc14ba9f060e 100644 --- a/opam/tezos_internal_brassaia_tests.opam +++ b/opam/tezos_internal_brassaia_tests.opam @@ -13,6 +13,7 @@ depends: [ "tezt" { with-test & >= "4.1.0" & < "5.0.0" } "bls12-381" {with-test} "octez-libs" {with-test} + "octez-shell-libs" {with-test} "octez-alcotezt" {with-test} "fpath" {with-test} "vector" {with-test} diff --git a/src/lib_node_config/dune b/src/lib_node_config/dune index 047410e8f4c6..dc46e71b0b63 100644 --- a/src/lib_node_config/dune +++ b/src/lib_node_config/dune @@ -12,7 +12,7 @@ octez-shell-libs.shell-services octez-libs.rpc-http octez-libs.rpc-http-server - octez-libs.tezos-context + octez-shell-libs.context-ops octez-shell-libs.store octez-shell-libs.validation) (flags @@ -24,6 +24,6 @@ -open Tezos_shell_services -open Tezos_rpc_http -open Tezos_rpc_http_server - -open Tezos_context + -open Tezos_context_ops -open Tezos_store -open Tezos_validation)) diff --git a/src/lib_protocol_environment/context_ops/context_ops.ml b/src/lib_protocol_environment/context_ops/context_ops.ml index 07de63d65c96..26aa2a5616f7 100644 --- a/src/lib_protocol_environment/context_ops/context_ops.ml +++ b/src/lib_protocol_environment/context_ops/context_ops.ml @@ -703,3 +703,7 @@ let compute_testchain_chain_id (context : Environment_context.t) block_hash = | Context {kind = Duo_memory_context.Context; _} -> Context_wrapper.Memory_context.compute_testchain_chain_id block_hash | Context t -> err_impl_mismatch ~got:t.impl_name + +let export_snapshot = assert false + +let integrity_check = assert false diff --git a/src/lib_protocol_environment/context_ops/context_ops.mli b/src/lib_protocol_environment/context_ops/context_ops.mli index d316594b6403..515225af7c96 100644 --- a/src/lib_protocol_environment/context_ops/context_ops.mli +++ b/src/lib_protocol_environment/context_ops/context_ops.mli @@ -190,3 +190,14 @@ val exists : index -> Context_hash.t -> bool Lwt.t val close : index -> unit Lwt.t val compute_testchain_chain_id : t -> Block_hash.t -> Chain_id.t + +val export_snapshot : index -> Context_hash.t -> path:string -> unit Lwt.t + +val integrity_check : + ?ppf:'a option -> + root:string -> + auto_repair:bool -> + always:bool -> + heads:string trace option -> + unit -> + unit Lwt.t diff --git a/src/lib_protocol_environment/test_shell_context/dune b/src/lib_protocol_environment/test_shell_context/dune index da2f7d4c4fc8..57ea9578a849 100644 --- a/src/lib_protocol_environment/test_shell_context/dune +++ b/src/lib_protocol_environment/test_shell_context/dune @@ -7,7 +7,7 @@ (libraries tezt.core bls12-381.archive - octez-shell-libs.shell-context + octez-shell-libs.context-ops octez-alcotezt octez-libs.test-helpers octez-libs.base diff --git a/src/lib_protocol_updater/dune b/src/lib_protocol_updater/dune index ce9ec02cadfe..ed4be641b5f5 100644 --- a/src/lib_protocol_updater/dune +++ b/src/lib_protocol_updater/dune @@ -13,7 +13,7 @@ octez-proto-libs.protocol-environment octez-protocol-compiler.registerer octez-protocol-compiler.native - octez-libs.tezos-context + octez-shell-libs.context-ops lwt-exit dynlink) (flags @@ -22,4 +22,4 @@ -open Tezos_stdlib_unix -open Tezos_micheline -open Tezos_shell_services - -open Tezos_context)) + -open Tezos_context_ops)) diff --git a/src/lib_shell/test/dune b/src/lib_shell/test/dune index 479f0be400c9..67cb95895981 100644 --- a/src/lib_shell/test/dune +++ b/src/lib_shell/test/dune @@ -12,9 +12,7 @@ octez-libs.base-test-helpers octez-shell-libs.store octez-shell-libs.store.shared - octez-libs.tezos-context octez-shell-libs.context-ops - octez-shell-libs.shell-context octez-shell-libs.protocol-updater octez-shell-libs.p2p octez-libs.tezos-p2p-services @@ -38,9 +36,7 @@ -open Tezos_base_test_helpers -open Tezos_store -open Tezos_store_shared - -open Tezos_context -open Tezos_context_ops - -open Tezos_shell_context -open Tezos_protocol_updater -open Tezos_p2p -open Tezos_p2p_services diff --git a/src/lib_shell/test/test_prevalidation.ml b/src/lib_shell/test/test_prevalidation.ml index 4744724708ab..6497c49de116 100644 --- a/src/lib_shell/test/test_prevalidation.ml +++ b/src/lib_shell/test/test_prevalidation.ml @@ -51,16 +51,15 @@ module Init = struct Lwt_utils_unix.with_tempdir "tezos_test_" (fun base_dir -> let open Lwt_result_syntax in let root = Filename.concat base_dir "context" in - let*! idx = Context.init root in + let*! idx = Context_ops.init ~kind:`Disk root in let* genesis = - Context.commit_genesis + Context_ops.commit_genesis idx ~chain_id ~time:Shell_test_helpers.genesis_time ~protocol:Shell_test_helpers.genesis_protocol_hash in - let*! v = Context.checkout_exn idx genesis in - let v = Tezos_shell_context.Shell_context.wrap_disk_context v in + let*! v = Context_ops.checkout_exn idx genesis in f v) let genesis_block ~timestamp ctxt = diff --git a/src/lib_store/unix/dune b/src/lib_store/unix/dune index 4c15ae27e83a..2108a8b3759b 100644 --- a/src/lib_store/unix/dune +++ b/src/lib_store/unix/dune @@ -88,7 +88,7 @@ octez-libs.stdlib-unix octez-libs.crypto octez-shell-libs.shell-services - octez-libs.tezos-context + octez-shell-libs.context-ops octez-shell-libs.validation octez-shell-libs.store.shared octez-shell-libs.store.unix) @@ -99,7 +99,7 @@ -open Tezos_stdlib_unix -open Tezos_crypto -open Tezos_shell_services - -open Tezos_context + -open Tezos_context_ops -open Tezos_validation -open Tezos_store_shared -open Tezos_store_unix) diff --git a/src/lib_store/unix/snapshots.ml b/src/lib_store/unix/snapshots.ml index 2af9ac3201f2..6d74cfce0eac 100644 --- a/src/lib_store/unix/snapshots.ml +++ b/src/lib_store/unix/snapshots.ml @@ -1459,7 +1459,7 @@ module type EXPORTER = sig unit Lwt.t val export_context : - t -> Context.index -> Context_hash.t -> unit tzresult Lwt.t + t -> Context_ops.index -> Context_hash.t -> unit tzresult Lwt.t val copy_cemented_block : t -> file:string -> start_level:int32 -> end_level:int32 -> unit Lwt.t @@ -1567,7 +1567,10 @@ module Raw_exporter : EXPORTER = struct Naming.(snapshot_context_file t.snapshot_tmp_dir |> file_path) in let*! () = - Context.export_snapshot context_index context_hash ~path:tmp_context_path + Context_ops.export_snapshot + context_index + context_hash + ~path:tmp_context_path in return_unit @@ -1813,7 +1816,10 @@ module Tar_exporter : EXPORTER = struct Naming.(snapshot_context_file t.snapshot_tmp_dir |> file_path) in let*! () = - Context.export_snapshot context_index context_hash ~path:tmp_context_path + Context_ops.export_snapshot + context_index + context_hash + ~path:tmp_context_path in let*! () = Onthefly.add_directory_and_finalize @@ -2457,8 +2463,10 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct let export_context snapshot_exporter ~context_dir context_hash = let open Lwt_result_syntax in let*! () = Event.(emit exporting_context) () in - let*! context_index = Context.init ~readonly:true context_dir in - let is_gc_allowed = Context.is_gc_allowed context_index in + let*! context_index = + Context_ops.init ~kind:`Disk ~readonly:true context_dir + in + let is_gc_allowed = Context_ops.is_gc_allowed context_index in let* () = if not is_gc_allowed then tzfail Cannot_export_snapshot_format else @@ -2469,7 +2477,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct Lwt.finalize (fun () -> Exporter.export_context snapshot_exporter context_index context_hash) - (fun () -> Context.close context_index) + (fun () -> Context_ops.close context_index) in let*! () = Event.(emit context_exported) () in return_unit @@ -3831,14 +3839,11 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct ~user_activated_protocol_overrides ~operation_metadata_size_limit = let open Lwt_result_syntax in let* predecessor_context = - let*! o = Context.checkout context_index imported_context_hash in + let*! o = Context_ops.checkout context_index imported_context_hash in match o with | Some ch -> return ch | None -> tzfail (Inconsistent_context imported_context_hash) in - let predecessor_context = - Tezos_shell_context.Shell_context.wrap_disk_context predecessor_context - in let apply_environment = { Block_validation.max_operations_ttl = @@ -3933,14 +3938,15 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct @@ fun () -> Importer.restore_context snapshot_importer ~dst_context_dir in let*! context_index = - Context.init + Context_ops.init + ~kind:`Disk ~readonly:false ~index_log_size:default_index_log_size ?patch_context dst_context_dir in let* genesis_ctxt_hash = - Context.commit_genesis + Context_ops.commit_genesis context_index ~chain_id ~time:genesis.Genesis.time @@ -3952,7 +3958,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct ~progress_display_mode:Auto ~msg:"Checking context integrity" @@ fun () -> - Context.Checks.Pack.Integrity_check.run + Context_ops.integrity_check ?ppf:None ~root:dst_context_dir ~auto_repair:false @@ -3975,7 +3981,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct ~user_activated_protocol_overrides ~operation_metadata_size_limit in - let*! () = Context.close context_index in + let*! () = Context_ops.close context_index in return (genesis_ctxt_hash, block_validation_result) in let* () = @@ -4074,15 +4080,6 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct snapshot_path user_expected_block in - let patch_context = - Option.map - (fun f ctxt -> - let open Tezos_shell_context in - let ctxt = Shell_context.wrap_disk_context ctxt in - let+ ctxt = f ctxt in - Shell_context.unwrap_disk_context ctxt) - patch_context - in (* Restore protocols *) let* protocol_levels = restore_protocols snapshot_importer progress_display_mode diff --git a/src/proto_020_PsParisC/lib_delegate/abstract_context_index.ml b/src/proto_020_PsParisC/lib_delegate/abstract_context_index.ml index 2e54f32fdc13..6dbf6c21d4b3 100644 --- a/src/proto_020_PsParisC/lib_delegate/abstract_context_index.ml +++ b/src/proto_020_PsParisC/lib_delegate/abstract_context_index.ml @@ -32,7 +32,7 @@ type t = { let abstract index = { - sync_fun = (fun () -> Context.sync index); - checkout_fun = Shell_context.checkout index; - finalize_fun = (fun () -> Context.close index); + sync_fun = (fun () -> Context_ops.sync index); + checkout_fun = Context_ops.checkout index; + finalize_fun = (fun () -> Context_ops.close index); } diff --git a/src/proto_020_PsParisC/lib_delegate/abstract_context_index.mli b/src/proto_020_PsParisC/lib_delegate/abstract_context_index.mli index 5a280d04ac57..4e2f52596c68 100644 --- a/src/proto_020_PsParisC/lib_delegate/abstract_context_index.mli +++ b/src/proto_020_PsParisC/lib_delegate/abstract_context_index.mli @@ -30,4 +30,4 @@ type t = { finalize_fun : unit -> unit Lwt.t; } -val abstract : Context.index -> t +val abstract : Context_ops.index -> t diff --git a/src/proto_020_PsParisC/lib_delegate/baking_simulator.ml b/src/proto_020_PsParisC/lib_delegate/baking_simulator.ml index 4184b4033f0d..84c09c7c5d27 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_simulator.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_simulator.ml @@ -38,7 +38,7 @@ type incremental = { let load_context ~context_path = let open Lwt_result_syntax in protect (fun () -> - let*! index = Context.init ~readonly:true context_path in + let*! index = Context_ops.init ~kind:`Disk ~readonly:true context_path in return (Abstract_context_index.abstract index)) let check_context_consistency (abstract_index : Abstract_context_index.t) diff --git a/src/proto_020_PsParisC/lib_delegate/dune b/src/proto_020_PsParisC/lib_delegate/dune index 94241009fc07..e28eeb9b3f49 100644 --- a/src/proto_020_PsParisC/lib_delegate/dune +++ b/src/proto_020_PsParisC/lib_delegate/dune @@ -19,8 +19,6 @@ octez-shell-libs.client-commands octez-libs.stdlib octez-libs.stdlib-unix - octez-shell-libs.shell-context - octez-libs.tezos-context octez-libs.rpc-http-client-unix octez-libs.rpc-http-client octez-shell-libs.context-ops @@ -46,8 +44,6 @@ -open Tezos_client_commands -open Tezos_stdlib -open Tezos_stdlib_unix - -open Tezos_shell_context - -open Tezos_context -open Tezos_rpc_http_client -open Tezos_context_ops -open Tezos_rpc_http diff --git a/src/proto_021_PsQuebec/lib_delegate/dune b/src/proto_021_PsQuebec/lib_delegate/dune index 5c29a9f2c275..5325387cfb7a 100644 --- a/src/proto_021_PsQuebec/lib_delegate/dune +++ b/src/proto_021_PsQuebec/lib_delegate/dune @@ -19,7 +19,6 @@ octez-shell-libs.client-commands octez-libs.stdlib octez-libs.stdlib-unix - octez-libs.tezos-context octez-libs.rpc-http-client-unix octez-libs.rpc-http-client octez-shell-libs.context-ops @@ -45,7 +44,6 @@ -open Tezos_client_commands -open Tezos_stdlib -open Tezos_stdlib_unix - -open Tezos_context -open Tezos_rpc_http_client -open Tezos_context_ops -open Tezos_rpc_http diff --git a/src/proto_alpha/lib_delegate/dune b/src/proto_alpha/lib_delegate/dune index dca3ff85f3fa..770e5f4e8fa3 100644 --- a/src/proto_alpha/lib_delegate/dune +++ b/src/proto_alpha/lib_delegate/dune @@ -19,7 +19,6 @@ octez-shell-libs.client-commands octez-libs.stdlib octez-libs.stdlib-unix - octez-libs.tezos-context octez-libs.rpc-http-client-unix octez-libs.rpc-http-client octez-shell-libs.context-ops @@ -45,7 +44,6 @@ -open Tezos_client_commands -open Tezos_stdlib -open Tezos_stdlib_unix - -open Tezos_context -open Tezos_rpc_http_client -open Tezos_context_ops -open Tezos_rpc_http -- GitLab From 82a8573aff0a196715e6f15fe7b7b3f782be8363 Mon Sep 17 00:00:00 2001 From: mattiasdrp Date: Tue, 15 Oct 2024 17:07:36 +0200 Subject: [PATCH 2/2] Context_ops: Add export_snapshot and integrity_check --- .../context_ops/context_ops.ml | 67 ++++++++++++++++++- .../context_ops/context_ops.mli | 6 +- .../duo_context_lib/context_wrapper.ml | 8 +++ src/lib_store/unix/snapshots.ml | 5 +- 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/lib_protocol_environment/context_ops/context_ops.ml b/src/lib_protocol_environment/context_ops/context_ops.ml index 26aa2a5616f7..db029ef36529 100644 --- a/src/lib_protocol_environment/context_ops/context_ops.ml +++ b/src/lib_protocol_environment/context_ops/context_ops.ml @@ -64,6 +64,14 @@ let err_impl_mismatch ~got = ~expected:"shell, memory, brassaia or brassaia_memory" ~got +let irmin_dir = "context" + +let brassaia_dir = "brassaia_context" + +let irmin_context_dir root = Filename.(concat root irmin_dir) + +let brassaia_context_dir root = Filename.(concat root brassaia_dir) + let init ~kind ?patch_context ?readonly ?index_log_size path = let open Lwt_syntax in let init_context () = @@ -704,6 +712,61 @@ let compute_testchain_chain_id (context : Environment_context.t) block_hash = Context_wrapper.Memory_context.compute_testchain_chain_id block_hash | Context t -> err_impl_mismatch ~got:t.impl_name -let export_snapshot = assert false +let export_snapshot context_index context_hash ~path = + match context_index with + | Disk_index index -> Context.export_snapshot index context_hash ~path + | Memory_index index -> + Tezos_context_memory.Context.export_snapshot index context_hash ~path + | Brassaia_index index -> Brassaia.export_snapshot index context_hash ~path + | Brassaia_memory_index index -> + Brassaia_memory.export_snapshot index context_hash ~path + | Duo_index index -> + Context_wrapper.Context.export_snapshot index context_hash ~path + | Duo_memory_index index -> + Context_wrapper.Memory_context.export_snapshot index context_hash ~path -let integrity_check = assert false +let integrity_check ?ppf ~root ~auto_repair ~always ~heads context_index = + let open Lwt_syntax in + match context_index with + | Disk_index _ -> + Context.Checks.Pack.Integrity_check.run + ?ppf + ~root:(irmin_context_dir root) + ~auto_repair + ~always + ~heads + () + | Memory_index _ -> + Fmt.failwith + "An in memory context doesn't need to be checked for integrity" + | Brassaia_index _ -> + Brassaia.Checks.Pack.Integrity_check.run + ?ppf + ~root:(brassaia_context_dir root) + ~auto_repair + ~always + ~heads + () + | Brassaia_memory_index _ -> + Fmt.failwith + "An in memory context doesn't need to be checked for integrity" + | Duo_index _ -> + let* () = + Context.Checks.Pack.Integrity_check.run + ?ppf + ~root:(irmin_context_dir root) + ~auto_repair + ~always + ~heads + () + in + Brassaia.Checks.Pack.Integrity_check.run + ?ppf + ~root:(brassaia_context_dir root) + ~auto_repair + ~always + ~heads + () + | Duo_memory_index _ -> + Fmt.failwith + "An in memory context doesn't need to be checked for integrity" diff --git a/src/lib_protocol_environment/context_ops/context_ops.mli b/src/lib_protocol_environment/context_ops/context_ops.mli index 515225af7c96..251ce5e06e54 100644 --- a/src/lib_protocol_environment/context_ops/context_ops.mli +++ b/src/lib_protocol_environment/context_ops/context_ops.mli @@ -194,10 +194,10 @@ val compute_testchain_chain_id : t -> Block_hash.t -> Chain_id.t val export_snapshot : index -> Context_hash.t -> path:string -> unit Lwt.t val integrity_check : - ?ppf:'a option -> + ?ppf:Format.formatter -> root:string -> auto_repair:bool -> always:bool -> - heads:string trace option -> - unit -> + heads:string list option -> + index -> unit Lwt.t diff --git a/src/lib_protocol_environment/duo_context_lib/context_wrapper.ml b/src/lib_protocol_environment/duo_context_lib/context_wrapper.ml index 4656d42d7962..089d81d4601e 100644 --- a/src/lib_protocol_environment/duo_context_lib/context_wrapper.ml +++ b/src/lib_protocol_environment/duo_context_lib/context_wrapper.ml @@ -1320,6 +1320,14 @@ struct "hash" block_hash1 + let export_snapshot : index -> Context_hash.t -> path:string -> unit Lwt.t = + fun index context_hash ~path -> + let open Lwt_syntax in + let* () = + Irmin_Context.export_snapshot index.irmin_index context_hash ~path + in + Brassaia_Context.export_snapshot index.brassaia_index context_hash ~path + let merkle_tree : t -> Proof.merkle_leaf_kind -> diff --git a/src/lib_store/unix/snapshots.ml b/src/lib_store/unix/snapshots.ml index 6d74cfce0eac..c926069aba63 100644 --- a/src/lib_store/unix/snapshots.ml +++ b/src/lib_store/unix/snapshots.ml @@ -3952,6 +3952,9 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct ~time:genesis.Genesis.time ~protocol:genesis.protocol in + (* TODO: Temporary fix before the context_dir is never provided + outside of context_ops *) + let dst_context_dir = Filename.dirname dst_context_dir in let*! () = if check_consistency then Animation.three_dots @@ -3964,7 +3967,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct ~auto_repair:false ~always:false ~heads:(Some [Context_hash.to_b58check imported_context_hash]) - () + context_index else Lwt.return_unit in let* block_validation_result = -- GitLab