123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 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. *)(* *)(*****************************************************************************)(* Every function of this file should check the feature flag. *)openAlpha_contextopenDal_errorsletassert_dal_feature_enabledctxt=letopenConstantsinletParametric.{dal={feature_enable;_};_}=parametricctxtinerror_unlessCompare.Bool.(feature_enable=true)Dal_feature_disabledletonly_if_dal_feature_enabledctxt~defaultf=letopenConstantsinletParametric.{dal={feature_enable;_};_}=parametricctxtiniffeature_enablethenfctxtelsedefaultctxtletslot_of_int_en=letopenTzresult_syntaxinmatchDal.Slot_index.of_intnwith|None->failDal_errors.Dal_slot_index_above_hard_limit|Someslot_index->returnslot_indexletvalidate_data_availabilityctxtdata_availability=assert_dal_feature_enabledctxt>>?fun()->letopenTzresult_syntaxinlet*max_index=slot_of_int_e@@((Constants.parametricctxt).dal.number_of_slots-1)inletmaximum_size=Dal.Endorsement.expected_size_in_bits~max_indexinletsize=Dal.Endorsement.occupied_size_in_bitsdata_availabilityinerror_unlessCompare.Int.(size<=maximum_size)(Dal_endorsement_size_limit_exceeded{maximum_size;got=size})letapply_data_availabilityctxtdata_availability~endorser=assert_dal_feature_enabledctxt>>?=fun()->letshards=Dal.Endorsement.shardsctxt~endorserinDal.Endorsement.record_available_shardsctxtdata_availabilityshards|>returnletvalidate_publish_slot_headerctxtDal.Slot.{index;_}=assert_dal_feature_enabledctxt>>?fun()->letopenTzresult_syntaxinletopenConstantsinletParametric.{dal={number_of_slots;_};_}=parametricctxtinlet*number_of_slots=slot_of_int_e(number_of_slots-1)inerror_unlessCompare.Int.(Dal.Slot_index.compareindexnumber_of_slots<=0||Dal.Slot_index.compareindexDal.Slot_index.zero>=0)(Dal_publish_slot_header_invalid_index{given=index;maximum=number_of_slots})letapply_publish_slot_headerctxtslot=assert_dal_feature_enabledctxt>>?fun()->Dal.Slot.register_slotctxtslot>>?fun(ctxt,updated)->ifupdatedthenokctxtelseerror(Dal_publish_slot_header_duplicate{slot})letdal_finalisationctxt=only_if_dal_feature_enabledctxt~default:(functxt->return(ctxt,None))(functxt->Dal.Slot.finalize_current_slotsctxt>>=functxt->Dal.Slot.finalize_pending_slotsctxt>|=?fun(ctxt,slot_availability)->(ctxt,Someslot_availability))