Module Mavryk_store_unix_snapshots.Snapshots

Snapshots for the store

Snapshots are canonical representations of the store and its associated context. Its main purposes it to save and load a current state with the minimal necessary amount of information. This snapshot may also be shared by third parties to facilitate the bootstrap process.

A snapshot of a block B is composed of :

There are two kinds of snapshot formats that can be exported:

Importing a snapshot will initialize a fresh store with the data contained in the snapshot. As snapshots may be shared between users, checks are made to ensure that no malicious data is loaded. For instance, we export the context of block B-1 to make sure that the application of the block B, given its predecessor's context, is valid.

Depending on the history mode, a snapshot might contain less blocks. In full, all blocks are present and importing such a snapshot will populate the Cemented_store with every cycle up to the snapshot's target block. Meanwhile, in Rolling, only a few previous blocks will be exported (max_op_ttl from the target block), only populating a Floating_block_store. Thus, the snapshot size greatly differs depending on the history mode used.

Snapshots may be created concurrently with a running node. It might impact the node for a few seconds to retrieve the necessary consistent information to produce the snapshot.

type Mavryk_base.TzPervasives.error +=
  1. | Incompatible_history_mode of {
    1. requested : Mavryk_shell_services.History_mode.t;
    2. stored : Mavryk_shell_services.History_mode.t;
    }
  2. | Invalid_export_block of {
    1. block : Mavryk_base.TzPervasives.Block_hash.t option;
    2. reason : [ `Pruned | `Pruned_pred | `Unknown | `Unknown_ancestor | `Caboose | `Genesis | `Not_enough_pred ];
    }
  3. | Invalid_export_path of string
  4. | Snapshot_file_not_found of string
  5. | Inconsistent_protocol_hash of {
    1. expected : Mavryk_base.TzPervasives.Protocol_hash.t;
    2. got : Mavryk_base.TzPervasives.Protocol_hash.t;
    }
  6. | Inconsistent_context_hash of {
    1. expected : Mavryk_base.TzPervasives.Context_hash.t;
    2. got : Mavryk_base.TzPervasives.Context_hash.t;
    }
  7. | Inconsistent_context of Mavryk_base.TzPervasives.Context_hash.t
  8. | Cannot_decode_protocol of Mavryk_base.TzPervasives.Protocol_hash.t
  9. | Cannot_write_metadata of string
  10. | Cannot_read of {
    1. kind : [ `Version | `Metadata | `Block_data | `Context | `Protocol_table | `Protocol | `Cemented_cycle ];
    2. path : string;
    }
  11. | Inconsistent_floating_store of Mavryk_store_shared.Store_types.block_descriptor * Mavryk_store_shared.Store_types.block_descriptor
  12. | Missing_target_block of Mavryk_store_shared.Store_types.block_descriptor
  13. | Cannot_read_floating_store of string
  14. | Cannot_retrieve_block_interval
  15. | Invalid_cemented_file of string
  16. | Missing_cemented_file of string
  17. | Corrupted_floating_store
  18. | Invalid_protocol_file of string
  19. | Target_block_validation_failed of Mavryk_base.TzPervasives.Block_hash.t * string
  20. | Directory_already_exists of string
  21. | Empty_floating_store
  22. | Cannot_remove_tmp_export_directory of string
  23. | Inconsistent_chain_import of {
    1. expected : Mavryk_base.TzPervasives.Distributed_db_version.Name.t;
    2. got : Mavryk_base.TzPervasives.Distributed_db_version.Name.t;
    }
  24. | Inconsistent_imported_block of Mavryk_base.TzPervasives.Block_hash.t * Mavryk_base.TzPervasives.Block_hash.t
type snapshot_format =
  1. | Tar
  2. | Raw
val pp_snapshot_format : Stdlib.Format.formatter -> snapshot_format -> unit
val snapshot_format_encoding : snapshot_format Mavryk_base.TzPervasives.Data_encoding.t
module Snapshot_header : sig ... end
val read_snapshot_header : snapshot_path:string -> Snapshot_header.t Mavryk_base.TzPervasives.tzresult Lwt.t

read_snapshot_header ~snapshot_path reads snapshot_file's header.

val export : ?snapshot_path:string -> snapshot_format -> ?rolling:bool -> block:Mavryk_shell_services.Block_services.block -> store_dir:string -> context_dir:string -> chain_name:Mavryk_base.TzPervasives.Distributed_db_version.Name.t -> progress_display_mode:Mavryk_stdlib_unix.Animation.progress_display_mode -> Mavryk_base.TzPervasives.Genesis.t -> unit Mavryk_base.TzPervasives.tzresult Lwt.t

export ?snapshot_path snapshot_format ?rolling ~block ~store_dir ~context_dir ~chain_name genesis ~progress_display_mode reads from the store_dir and context_dir the current state of the node and produces a snapshot, of the given snapshot_format, in snapshot_file if it is provided. Otherwise, a snapshot file name is automatically generated using the target block as hint. If rolling is set, only the necessary blocks will be exported.

val import : snapshot_path:string -> ?patch_context: (Mavryk_protocol_environment.Context.t -> Mavryk_protocol_environment.Context.t Mavryk_base.TzPervasives.tzresult Lwt.t) -> ?block:Mavryk_base.TzPervasives.Block_hash.t -> ?check_consistency:bool -> dst_store_dir:string -> dst_context_dir:string -> chain_name:Mavryk_base.TzPervasives.Distributed_db_version.Name.t -> configured_history_mode:Mavryk_shell_services.History_mode.t option -> user_activated_upgrades:Mavryk_base.TzPervasives.User_activated.upgrades -> user_activated_protocol_overrides: Mavryk_base.TzPervasives.User_activated.protocol_overrides -> operation_metadata_size_limit: Mavryk_shell_services.Shell_limits.operation_metadata_size_limit -> progress_display_mode:Mavryk_stdlib_unix.Animation.progress_display_mode -> Mavryk_base.TzPervasives.Genesis.t -> unit Mavryk_base.TzPervasives.tzresult Lwt.t

import ~snapshot_path ?patch_context ?block ?check_consistency ~dst_store_dir ~dst_context_dir chain_name ~user_activated_upgrades ~user_activated_protocol_overrides ~ops_metadata_size_limit genesis populates dst_store_dir and dst_context_dir with the data contained in the snapshot_file. If check_consistency is unset, less security checks will be made and the import process will be more efficient. If block is set, the import process will make sure that the block is the correct one we load. patch_context, user_activated_upgrades and user_activated_protocol_overrides are passed to the validator in order to validate the target block. ops_metadata_size_limit determines the maximal size of the metadata to store while importing a snapshot.

val snapshot_file_kind : snapshot_path:string -> snapshot_format Mavryk_base.TzPervasives.tzresult Lwt.t

snapshot_file_kind ~snapshot_file reads the snapshot_file and returns its kind. Returns Invalid if it is a wrong snapshot file.