123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130(*****************************************************************************)(* *)(* Open Source License *)(* 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. *)(* *)(*****************************************************************************)typeerror+=Unsupported_protocolofProtocol_hash.tlet()=register_error_kind~id:"smart_rollup.node.unsupported_protocol"~title:"Protocol not supported by rollup node"~description:"Protocol not supported by rollup node."~pp:(funppfproto->Format.fprintfppf"Protocol %a is not supported by the rollup node."Protocol_hash.ppproto)`PermanentData_encoding.(obj1(req"protocol"Protocol_hash.encoding))(functionUnsupported_protocolp->Somep|_->None)(funp->Unsupported_protocolp)typeproto_plugin=(moduleProtocol_plugin_sig.S)letproto_plugins:proto_pluginProtocol_hash.Table.t=Protocol_hash.Table.create7letregister(plugin:proto_plugin)=letmodulePlugin=(valplugin)inifProtocol_hash.Table.memproto_pluginsPlugin.protocolthenFormat.kasprintfinvalid_arg"The rollup node protocol plugin for protocol %a is already registered. \
Did you register it manually multiple times?"Protocol_hash.ppPlugin.protocol;Protocol_hash.Table.addproto_pluginsPlugin.protocolpluginletregistered_protocols()=Protocol_hash.Table.to_seq_keysproto_plugins|>List.of_seqletproto_plugin_for_protocolprotocol=Protocol_hash.Table.findproto_pluginsprotocol|>Option.to_result~none:[Unsupported_protocolprotocol]letproto_plugin_for_levelnode_ctxtlevel=letopenLwt_result_syntaxinlet*{protocol;_}=Node_context.protocol_of_levelnode_ctxtlevelinlet*?plugin=proto_plugin_for_protocolprotocolinreturnpluginletproto_plugin_for_level_with_storenode_storelevel=letopenLwt_result_syntaxinlet*{protocol;_}=Node_context.protocol_of_level_with_storenode_storelevelinlet*?plugin=proto_plugin_for_protocolprotocolinreturnpluginletproto_plugin_for_blocknode_ctxtblock_hash=letopenLwt_result_syntaxinlet*level=Node_context.level_of_hashnode_ctxtblock_hashinproto_plugin_for_levelnode_ctxtlevelletlast_proto_pluginnode_ctxt=letopenLwt_result_syntaxinlet*protocol=Node_context.last_seen_protocolnode_ctxtinmatchprotocolwith|None->failwith"No known last protocol, cannot get plugin"|Someprotocol->let*?plugin=proto_plugin_for_protocolprotocolinreturnpluginmoduleConstants_cache=Aches_lwt.Lache.Make_result(Aches.Rache.Transfer(Aches.Rache.LRU)(Protocol_hash))letconstants_cache=letcache_size=3inConstants_cache.createcache_sizeletget_constants_of_protocol(node_ctxt:_Node_context.t)protocol_hash=letopenLwt_result_syntaxinifProtocol_hash.(protocol_hash=node_ctxt.current_protocol.hash)thenreturnnode_ctxt.current_protocol.constantselseletretrieveprotocol_hash=let*?plugin=proto_plugin_for_protocolprotocol_hashinletmodulePlugin=(valplugin)inlet*(First_knownl|Activation_levell)=Node_context.protocol_activation_levelnode_ctxtprotocol_hashinPlugin.Layer1_helpers.retrieve_constants~block:(`Levell)node_ctxt.cctxtinConstants_cache.bind_or_putconstants_cacheprotocol_hashretrieveLwt.returnletget_constants_of_levelnode_ctxtlevel=letopenLwt_result_syntaxinlet*{protocol;_}=Node_context.protocol_of_levelnode_ctxtlevelinget_constants_of_protocolnode_ctxtprotocolletget_constants_of_block_hashnode_ctxtblock_hash=letopenLwt_result_syntaxinlet*level=Node_context.level_of_hashnode_ctxtblock_hashinget_constants_of_levelnode_ctxtlevel