123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 Nomadic Labs, <contact@nomadic-labs.com> *)(* Copyright (c) 2023 Functori, <contact@functori.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. *)(* *)(*****************************************************************************)includeStore_sigsincludeStore_utilsincludeStore_v0letversion=Store_version.V1moduleMake_hash_index_key(H:Tezos_crypto.Intfs.HASH)=Indexed_store.Make_index_key(structincludeIndexed_store.Make_fixed_encodable(H)letequal=H.equalend)(** Unaggregated messages per block *)moduleMessages=Indexed_store.Make_indexed_file(structletname="messages"end)(Make_hash_index_key(Merkelized_payload_hashes_hash))(structtypet=stringlistletname="messages_list"letencoding=Data_encoding.(list@@dynamic_sizeVariable.(string'Hex))moduleHeader=structtypet=bool*Block_hash.t*Time.Protocol.t*intletname="messages_inbox_info"letencoding=letopenData_encodinginobj4(req"is_first_block"bool)(req"predecessor"Block_hash.encoding)(req"predecessor_timestamp"Time.Protocol.encoding)(req"num_messages"int31)letfixed_size=WithExceptions.Option.get~loc:__LOC__@@Data_encoding.Binary.fixed_lengthencodingendend)moduleDal_pages=structtyperemoved_in_v1endmoduleDal_processed_slots=structtyperemoved_in_v1end(** Store attestation statuses for DAL slots on L1. *)moduleDal_slots_statuses=Irmin_store.Make_nested_map(structletpath=["dal";"slots_statuses"]end)(structtypekey=Block_hash.tletto_path_representation=Block_hash.to_b58checkend)(structtypekey=Dal.Slot_index.tletencoding=Dal.Slot_index.encodingletcompare=Compare.Int.compareletname="slot_index"end)(struct(* TODO: https://gitlab.com/tezos/tezos/-/issues/4780.
Rename Confirm-ed/ation to Attest-ed/ation in the rollup node. *)typevalue=[`Confirmed|`Unconfirmed]letname="slot_status"letencoding=(* We don't use
Data_encoding.string_enum because a union is more storage-efficient. *)letopenData_encodinginunion~tag_size:`Uint8[case~title:"Confirmed"(Tag0)(obj1(req"kind"(constant"Confirmed")))(function`Confirmed->Some()|`Unconfirmed->None)(fun()->`Confirmed);case~title:"Unconfirmed"(Tag1)(obj1(req"kind"(constant"Unconfirmed")))(function`Unconfirmed->Some()|`Confirmed->None)(fun()->`Unconfirmed);]end)typenonrec'astore={l2_blocks:'aL2_blocks.t;messages:'aMessages.t;inboxes:'aInboxes.t;commitments:'aCommitments.t;commitments_published_at_level:'aCommitments_published_at_level.t;l2_head:'aL2_head.t;last_finalized_level:'aLast_finalized_level.t;levels_to_hashes:'aLevels_to_hashes.t;irmin_store:'aIrmin_store.t;}type'at=([<`Read|`Write>`Read]as'a)storetyperw=Store_sigs.rwttypero=Store_sigs.rotletreadonly({l2_blocks;messages;inboxes;commitments;commitments_published_at_level;l2_head;last_finalized_level;levels_to_hashes;irmin_store;}:_t):ro={l2_blocks=L2_blocks.readonlyl2_blocks;messages=Messages.readonlymessages;inboxes=Inboxes.readonlyinboxes;commitments=Commitments.readonlycommitments;commitments_published_at_level=Commitments_published_at_level.readonlycommitments_published_at_level;l2_head=L2_head.readonlyl2_head;last_finalized_level=Last_finalized_level.readonlylast_finalized_level;levels_to_hashes=Levels_to_hashes.readonlylevels_to_hashes;irmin_store=Irmin_store.readonlyirmin_store;}letclose({l2_blocks;messages;inboxes;commitments;commitments_published_at_level;l2_head=_;last_finalized_level=_;levels_to_hashes;irmin_store;}:_t)=letopenLwt_result_syntaxinlet+()=L2_blocks.closel2_blocksand+()=Messages.closemessagesand+()=Inboxes.closeinboxesand+()=Commitments.closecommitmentsand+()=Commitments_published_at_level.closecommitments_published_at_leveland+()=Levels_to_hashes.closelevels_to_hashesand+()=Irmin_store.closeirmin_storein()letload(typea)(mode:amode)~l2_blocks_cache_sizedata_dir:astoretzresultLwt.t=letopenLwt_result_syntaxinletpathname=Filename.concatdata_dirnameinletcache_size=l2_blocks_cache_sizeinlet*l2_blocks=L2_blocks.loadmode~path:(path"l2_blocks")~cache_sizeinlet*messages=Messages.loadmode~path:(path"messages")~cache_sizeinlet*inboxes=Inboxes.loadmode~path:(path"inboxes")~cache_sizeinlet*commitments=Commitments.loadmode~path:(path"commitments")inlet*commitments_published_at_level=Commitments_published_at_level.loadmode~path:(path"commitments_published_at_level")inlet*l2_head=L2_head.loadmode~path:(path"l2_head")inlet*last_finalized_level=Last_finalized_level.loadmode~path:(path"last_finalized_level")inlet*levels_to_hashes=Levels_to_hashes.loadmode~path:(path"levels_to_hashes")inlet+irmin_store=Irmin_store.loadmode(path"irmin_store")in{l2_blocks;messages;inboxes;commitments;commitments_published_at_level;l2_head;last_finalized_level;levels_to_hashes;irmin_store;}letiter_l2_blocks({l2_blocks;l2_head;_}:_t)f=letopenLwt_result_syntaxinlet*head=L2_head.readl2_headinmatchheadwith|None->(* No reachable head, nothing to do *)return_unit|Somehead->letrecloophash=let*block=L2_blocks.readl2_blockshashinmatchblockwith|None->(* The block does not exist, the known chain stops here, so do we. *)return_unit|Some(block,header)->let*()=f{blockwithheader}inloopheader.predecessorinloophead.header.block_hash