123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2019-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. *)(* *)(*****************************************************************************)typeadditional_cycles={offset:int}letpp_additional_cyclesppf{offset}=Format.pp_print_stringppf(ifoffset=0then""elseFormat.sprintf" + %d extra cycles"offset)(* For Full and Rolling modes, setting `additional_cycles` to `None`
specifies that the history mode will depend on the default
offset. Thus, if this `default_offset` value is modified at some
point, the data will be automatically updated to meet the new
requirements in terms of data retention. On the contrary, the usage
of `Some N` additional cycles fixes it to `N`.*)typet=|Archive|Fullofadditional_cyclesoption|Rollingofadditional_cyclesoption(* The default_offset value defines a window of stored cycles which is
suitable for baking services. It currently corresponds to 6 as we
store 1 cycle below the last allowed fork level of the current
head, which is set to [preserved_cycles] cycles in the past.
TODO: https://gitlab.com/tezos/tezos/-/issues/1406
As this value is potentially both network and protocol specific, it
could be lifted as a protocol value or an hardcoded node
configuration argument. *)letdefault_offset=1letdefault_additional_cycles={offset=default_offset}letdefault_full=FullNoneletdefault_rolling=RollingNoneletdefault=default_fullmoduleLegacy=structtypet=Archive|Full|Rollingletencoding=Data_encoding.string_enum[("archive",Archive);("full",Full);("rolling",Rolling)]letppppf=function|Archive->Format.fprintfppf"archive"|Full->Format.fprintfppf"full"|Rolling->Format.fprintfppf"rolling"endletconvert=function|Legacy.Rolling->default_rolling|Legacy.Full->default_full|Legacy.Archive->Archiveletadditional_cycles_encoding=letopenData_encodinginobj1(req~title:"additional cycles"~description:(Format.sprintf"Number of additional cycles preserved below the savepoint. By \
default: %d additional cycles will be stored."default_additional_cycles.offset)"additional_cycles"(ranged_int01_000))letencoding=letopenData_encodingindef"history_mode"~title:"history mode"~description:"Storage mode for the Tezos shell."(union~tag_size:`Uint8[case~title:"archive"~description:"Archive mode retains every block and operations since the \
genesis block including their metadata and their associated \
contexts."(Tag0)(constant"archive")(functionArchive->Some()|_->None)(fun()->Archive);case~title:"full"~description:"Full mode retains every block and operations since the genesis \
block but periodically prunes older blocks' metadata to reduce \
the storage size."(Tag1)(obj1(req"full"additional_cycles_encoding))(function|Full(Some{offset})->Someoffset|FullNone->None|_->None)(functionoffset->Full(Some{offset}));case~title:"rolling"~description:"Rolling mode only retain the most recent cycles by periodically \
periodically discarding older blocks to reduce the storage size."(Tag2)(obj1(req"rolling"additional_cycles_encoding))(function|Rolling(Some{offset})->Someoffset|RollingNone->None|_->None)(functionoffset->Rolling(Some{offset}));(* Cases with default numbers of additional cycles. Using
them in the configuration file ensures that new default
values are used after updating instead of being pinned to
an explicit value. *)case~title:"full_alias"~description:"Full mode with default number of additional cycles."(Tag3)(constant"full")(functionFullNone->Some()|_->None)(fun()->default_full);case~title:"rolling_alias"~description:"Rolling mode with default number of additional cycles."(Tag4)(constant"rolling")(functionRollingNone->Some()|_->None)(fun()->default_rolling);])letequalhm1hm2=match(hm1,hm2)with|Archive,Archive|FullNone,FullNone|RollingNone,RollingNone->true|Full(Some{offset}),Full(Some{offset=offset'})|Rolling(Some{offset}),Rolling(Some{offset=offset'})->Compare.Int.(offset=offset')|(full,Full(Some{offset})|Full(Some{offset}),full)whenoffset=default_offset&&full=default_full->true|(rolling,Rolling(Some{offset})|Rolling(Some{offset}),rolling)whenoffset=default_offset&&rolling=default_rolling->true|_->falseletmode_equalityhm1hm2=match(hm1,hm2)with|Archive,Archive|Full_,Full_|Rolling_,Rolling_->true|Archive,_|Full_,_|Rolling_,_->falseletppppf=function|Archive->Format.fprintfppf"Archive mode"|FullNone->Format.fprintfppf"Full mode%a"pp_additional_cyclesdefault_additional_cycles|RollingNone->Format.fprintfppf"Rolling mode%a"pp_additional_cyclesdefault_additional_cycles|Full(Someadditional_cycles)->Format.fprintfppf"Full mode%a"pp_additional_cyclesadditional_cycles|Rolling(Someadditional_cycles)->Format.fprintfppf"Rolling mode%a"pp_additional_cyclesadditional_cyclesletpp_shortppf=function|Archive->Format.fprintfppf"archive"|Full_->Format.fprintfppf"full"|Rolling_->Format.fprintfppf"rolling"lettag=Tag.def"history_mode"pp