123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contextmodulePlugin=structmoduleProto=Registerer.Registeredtypeblock_info=Protocol_client_context.Alpha_block_services.block_infoletparametric_constantschainblockctxt=letcpctxt=newProtocol_client_context.wrap_rpc_contextctxtinProtocol.Constants_services.parametriccpctxt(chain,block)letget_constantschainblockctxt=letopenLwt_result_syntaxinlet*parametric=parametric_constantschainblockctxtinlet{Constants.Parametric.feature_enable;number_of_slots;attestation_lag;attestation_threshold;cryptobox_parameters;blocks_per_epoch=_;}=parametric.dalinreturn{Dal_plugin.feature_enable;incentives_enable=false;number_of_slots;attestation_lag;attestation_threshold;cryptobox_parameters;sc_rollup_challenge_window_in_blocks=parametric.sc_rollup.challenge_window_in_blocks;commitment_period_in_blocks=parametric.sc_rollup.commitment_period_in_blocks;dal_attested_slots_validity_lag=Int.max_int;}letblock_info?chain?block~metadatactxt=letcpctxt=newProtocol_client_context.wrap_rpc_contextctxtinProtocol_client_context.Alpha_block_services.infocpctxt?chain?block~metadata()letblock_shell_header(block_info:block_info)=block_info.header.shellletget_roundfitness=letopenResult_syntaxinlet*round=Fitness.round_from_rawfitness|>Environment.wrap_tzresultinreturn@@Round.to_int32round(* Turn the given value of type {!Protocol.Apply_operation_result.operation_result}
into a value of type {!Dal_plugin.operation_application_result}. *)letstatus_of_result=function|Protocol.Apply_operation_result.Applied_->Dal_plugin.Succeeded|_->Dal_plugin.Failedletget_published_slot_headers(block:block_info)=letopenLwt_result_syntaxinletopenProtocol.Alpha_contextinletapply_internalacc~source:__op_res=accinletapply(typekind)acc~source:_(op:kindmanager_operation)(result:(kind,_,_)Protocol.Apply_operation_result.operation_result)=matchopwith|Dal_publish_slot_headeroperation->(operation.slot_index,operation.commitment,status_of_resultresult)::acc|_->accinLayer1_services.(process_manager_operations[]block.operations{apply;apply_internal})|>List.map_es(fun(slot_index,commitment,status)->letpublished_level=block.header.shell.levelinletslot_index=Dal.Slot_index.to_intslot_indexinreturnDal_plugin.({published_level;slot_index;commitment},status))letget_committeectxt~level=letopenLwt_result_syntaxinletcpctxt=newProtocol_client_context.wrap_rpc_contextctxtinlet*?level=Raw_level.of_int32level|>Environment.wrap_tzresultinlet+pkh_to_shards=Plugin.RPC.Dal.dal_shardscpctxt(`Main,`Head0)~level()inletindexes(initial_slot,power)=letlast_slot=initial_slot+power-1inletreciteracci=ifi<initial_slotthenaccelseiter(i::acc)(i-1)initer[]last_slotinList.fold_left(funacc(pkh,s)->Signature.Public_key_hash.Map.addpkh(indexess)acc)Signature.Public_key_hash.Map.emptypkh_to_shardsletattested_slot_headers(block:block_info)~number_of_slots=letopenResult_syntaxinlet*metadata=Option.to_resultblock.metadata~none:(TzTrace.make@@Layer1_services.Cannot_read_block_metadatablock.hash)inletconfirmed_slots=Option.value~default:Dal.Attestation.emptymetadata.protocol_data.dal_attestationinlet*all_slots=Dal.Slot_index.slots_range~number_of_slots~lower:0~upper:(number_of_slots-1)|>Environment.wrap_tzresultinList.filter(Dal.Attestation.is_attestedconfirmed_slots)all_slots|>Dal.Slot_index.to_int_list|>return(* Section of helpers for Skip lists *)moduleSkip_list=structtypecell=Dal.Slots_history.ttypehash=Dal.Slots_history.Pointer_hash.tletcell_encoding=Dal.Slots_history.encodinglethash_encoding=Dal.Slots_history.Pointer_hash.encodingletcell_equal=Dal.Slots_history.equallethash_equal=Dal.Slots_history.Pointer_hash.equalletcell_hash=Dal.Slots_history.hash(* We return the empty list here because DAL is not activated in Oxford2. *)letcells_of_level_block_info_ctxt=Lwt_result_syntax.return[]endmoduleRPC=structletdirectory_skip_list_cells_store=Tezos_rpc.Directory.emptyendendlet()=Dal_plugin.register(modulePlugin)