123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020-2021 Nomadic Labs, <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openFilename.InfixopenStore_typestype'dirnamedirectory={dir_path:string}type'kindfile={file_path:string}type('kind,'data)encoded_file='dataStored_data.fileletdir_path{dir_path}=dir_pathletfile_path{file_path}=file_pathletis_json_filefile=file.Stored_data.jsonletmake_encoded_file?(json=false)dir~filenameencodingeq=letfilepath=dir_pathdir//filenameinStored_data.make_file~json~filepathencodingeqletencoded_file_path{Stored_data.path;_}=pathletfile_encoding{Stored_data.encoding;_}=encoding(* Utility functions *)letmk_filedirname={file_path=dir.dir_path//name}letmk_dirdirdir_name={dir_path=dir.dir_path//dir_name}letstore_dir~dir_path={dir_path}letprotocol_store_dirbase_dir=mk_dirbase_dir"protocols"letprotocol_filedirproto_hash=mk_filedir(Protocol_hash.to_b58checkproto_hash)letchain_dirdirchain_id=mk_dirdir(Format.asprintf"chain_%a"Chain_id.pp_shortchain_id)letchain_config_filedir=make_encoded_file~json:truedir~filename:"config.json"chain_config_encodingchain_config_equalletlock_filedir=mk_filedir"lock"letgc_lockfiledir=mk_filedir"gc_lock"letreconstruction_lock_filedir=mk_filedir"reconstruction_lock"lettestchains_dirdir=mk_dirdir"testchains"letprotocol_levels_filedir=make_encoded_filedir~filename:"protocol_levels"Protocol_levels.encodingStore_types.Protocol_levels.equalletlegacy_protocol_levels_filedir=make_encoded_filedir~filename:"protocol_levels"Protocol_levels.Legacy.encodingProtocol_levels.Legacy.equalletgenesis_block_filedir=make_encoded_filedir~filename:"genesis"Block_repr.encodingBlock_repr.equalletcurrent_head_filedir=make_encoded_filedir~filename:"current_head"block_descriptor_encodingblock_descriptor_equalletcementing_highwatermark_filedir=make_encoded_filedir~filename:"cementing_highwatermark"Data_encoding.(optionint32)(Option.equalInt32.equal)letcheckpoint_filedir=make_encoded_filedir~filename:"checkpoint"block_descriptor_encodingblock_descriptor_equallettarget_filedir=make_encoded_filedir~filename:"target"(Data_encoding.optionblock_descriptor_encoding)(Option.equalblock_descriptor_equal)letinvalid_blocks_filedir=make_encoded_filedir~filename:"invalid_blocks"(Block_hash.Map.encodinginvalid_block_encoding)(Block_hash.Map.equalinvalid_block_equal)letforked_chains_filedir=make_encoded_filedir~filename:"forked_chains"(Chain_id.Map.encodingBlock_hash.encoding)(Chain_id.Map.equalBlock_hash.equal)letsavepoint_filedir=make_encoded_filedir~filename:"savepoint"block_descriptor_encodingStore_types.block_descriptor_equalletcaboose_filedir=make_encoded_filedir~filename:"caboose"block_descriptor_encodingStore_types.block_descriptor_equaltypeblock_store_status=Idle|Mergingletblock_store_status_encoding=letopenData_encodinginconv(functionIdle->false|Merging->true)(functionfalse->Idle|true->Merging)boolletstatus_equals1s2=match(s1,s2)with|Idle,Idle->true|Merging,Merging->true|Idle,Merging|Merging,Idle->falseletblock_store_status_filedir=make_encoded_filedir~filename:"status"block_store_status_encodingstatus_equalletcemented_blocks_dirdir=mk_dirdir"cemented"letcemented_blocks_level_index_dirdir=mk_dirdir"level_index"letcemented_blocks_level_lock_filedir=mk_filedir(Filename.concat"index""lock")letcemented_blocks_hash_index_dirdir=mk_dirdir"hash_index"letcemented_blocks_hash_lock_filedir=mk_filedir(Filename.concat"index""lock")letcemented_blocks_filedir~start_level~end_level=mk_filedir(Printf.sprintf"%ld_%ld"start_levelend_level)letcemented_blocks_metadata_dirdir=mk_dirdir"metadata"letcemented_blocks_metadata_filedir{file_path}=mk_filedir(Filename.basenamefile_path^".zip")letcemented_blocks_tmp_metadata_filedir{file_path}=mk_filedir(Filename.basenamefile_path^".zip.part")typefloating_kind=RO|RW|RW_TMP|RO_TMP|Restoreoffloating_kindletfloating_blocks_dirdirkind=letrecloop=function|RO->"ro_floating"|RW->"rw_floating"|RO_TMP->"ro_tmp_floating"|RW_TMP->"rw_tmp_floating"|Restorekind->"restore_"^loopkindinmk_dirdir(loopkind)letfloating_blocks_index_dirdir=mk_dirdir"index"letfloating_blocks_filedir=mk_filedir"blocks"letsnapshot_dir?snapshot_path()=letsnapshot_path=matchsnapshot_pathwithSomepath->path|None->"tezos-snapshot"in{dir_path=snapshot_path}letsnapshot_file~snapshot_filenamedir=mk_filedirsnapshot_filenameletsnapshot_tmp_dirsnapshot_dir={dir_path=snapshot_dir.dir_path^"_tmp"}letsnapshot_tmp_tar_filedir=mk_filedir"tmp_snapshot.tar"letsnapshot_block_data_filedir=mk_filedir"block_data"letsnapshot_context_filedir=mk_filedir"context"letsnapshot_floating_blocks_filedir=mk_filedir"floating_blocks"letsnapshot_metadata_filedir=mk_filedir"metadata.json"letsnapshot_version_filedir=mk_filedir"snapshot_version.json"letsnapshot_protocol_levels_filedir=make_encoded_filedir~filename:"protocol_levels"Protocol_levels.encodingProtocol_levels.equalletsnapshot_tar_root={dir_path=""}