123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Nomadic Development. <contact@tezcore.com> *)(* Copyright (c) 2018-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. *)(* *)(*****************************************************************************)moduletypeFILTER=sigmoduleProto:Registered_protocol.TmoduleMempool:sigtypeconfigvalconfig_encoding:configData_encoding.tvaldefault_config:configtypestatevalinit:Tezos_protocol_environment.Context.t->head:Tezos_base.Block_header.shell_header->statetzresultLwt.tvalflush:state->head:Tezos_base.Block_header.shell_header->statetzresultLwt.tvalremove:filter_state:state->Operation_hash.t->statevalsyntactic_check:Proto.operation->[`Well_formed|`Ill_formed]Lwt.tvalpre_filter:config->filter_state:state->Proto.operation->[`Passed_prefilterof[`High|`Medium|`LowofQ.tlist]|`Branch_delayedoftztrace|`Branch_refusedoftztrace|`Refusedoftztrace|`Outdatedoftztrace]Lwt.tvaladd_operation_and_enforce_mempool_bound:?replace:Operation_hash.t->config->state->Operation_hash.t*Proto.operation->(state*[`No_replace|`ReplaceofOperation_hash.t*[`Branch_delayedoftztrace|`Branch_refusedoftztrace|`Refusedoftztrace|`Outdatedoftztrace]],[`Branch_delayedoftztrace|`Branch_refusedoftztrace|`Refusedoftztrace|`Outdatedoftztrace])resultLwt.tvalconflict_handler:config->Proto.Mempool.conflict_handlerendendmoduletypeRPC=sigmoduleProto:Registered_protocol.Tvalrpc_services:Tezos_protocol_environment.rpc_contextTezos_rpc.Directory.directoryendmoduleNo_filter(Proto:Registered_protocol.T):FILTERwithmoduleProto=ProtoandtypeMempool.state=unit=structmoduleProto=ProtomoduleMempool=structtypeconfig=unitletconfig_encoding=Data_encoding.emptyletdefault_config=()typestate=unitletinit_~head:_=Lwt_result_syntax.return_unitletremove~filter_state_=filter_stateletflush_~head:_=Lwt_result_syntax.return_unitletsyntactic_check_=Lwt.return`Well_formedletpre_filter_~filter_state:__=Lwt.return@@`Passed_prefilter(`Low[])letadd_operation_and_enforce_mempool_bound?replace:__filter_state_=Lwt_result.return(filter_state,`No_replace)letconflict_handler_~existing_operation~new_operation=ifProto.compare_operationsexisting_operationnew_operation<0then`Replaceelse`KeependendmoduletypeMETRICS=sigvalhash:Protocol_hash.tvalupdate_metrics:protocol_metadata:bytes->Fitness.t->(cycle:float->consumed_gas:float->round:float->unit)->unitLwt.tendmoduleUndefined_metrics_plugin(Proto:sigvalhash:Protocol_hash.tend)=structlethash=Proto.hashletupdate_metrics~protocol_metadata:___=Lwt.return_unitendletrpc_table:(moduleRPC)Protocol_hash.Table.t=Protocol_hash.Table.create5letmetrics_table:(moduleMETRICS)Protocol_hash.Table.t=Protocol_hash.Table.create5letregister_rpc(moduleRpc:RPC)=assert(not(Protocol_hash.Table.memrpc_tableRpc.Proto.hash));Protocol_hash.Table.addrpc_tableRpc.Proto.hash(moduleRpc)letregister_metrics(moduleMetrics:METRICS)=Protocol_hash.Table.replacemetrics_tableMetrics.hash(moduleMetrics)letfind_rpc=Protocol_hash.Table.findrpc_tableletfind_metrics=Protocol_hash.Table.findmetrics_tableletsafe_find_metricshash=matchfind_metricshashwith|Someproto_metrics->Lwt.returnproto_metrics|None->letmoduleMetrics=Undefined_metrics_plugin(structlethash=hashend)inLwt.return(moduleMetrics:METRICS)letfilter_table:(moduleFILTER)Protocol_hash.Table.t=Protocol_hash.Table.create5letadd_to_filter_tableproto_hashfilter=assert(not(Protocol_hash.Table.memfilter_tableproto_hash));Protocol_hash.Table.addfilter_tableproto_hashfilterletregister_filter(moduleFilter:FILTER)=add_to_filter_tableFilter.Proto.hash(moduleFilter)letvalidator_filter_not_found=Internal_event.Simple.declare_1~section:["block";"validation"]~name:"protocol_filter_not_found"~msg:"no protocol filter found for protocol {protocol_hash}"~level:Warning~pp1:Protocol_hash.pp("protocol_hash",Protocol_hash.encoding)letfind_filter~block_hashprotocol_hash=letopenLwt_result_syntaxinmatchProtocol_hash.Table.findfilter_tableprotocol_hashwith|Somefilter->returnfilter|None->(matchRegistered_protocol.getprotocol_hashwith|None->tzfail(Block_validator_errors.Unavailable_protocol{block=block_hash;protocol=protocol_hash})|Some(moduleProto:Registered_protocol.T)->let*!()=matchProto.environment_versionwith|V0->(* This is normal for protocols Genesis and 000
because they don't have a plugin. *)Lwt.return_unit|_->Internal_event.Simple.(emitvalidator_filter_not_found)protocol_hashinreturn(moduleNo_filter(Proto):FILTER))