123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182(*****************************************************************************)(* *)(* 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->statevalpre_filter:config->filter_state:state->Proto.operation->[`Passed_prefilterofPrevalidator_pending_operations.priority|Prevalidator_classification.error_classification]Lwt.tvaladd_operation_and_enforce_mempool_bound:?replace:Operation_hash.t->config->state->Operation_hash.t*Proto.operation->(state*[`No_replace|`ReplaceofOperation_hash.t*Prevalidator_classification.error_classification],Prevalidator_classification.error_classification)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_unitletpre_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)typefilter_t=|Recentof(moduleFILTER)|Legacyof(moduleLegacy_mempool_plugin.FILTER)letis_recent_proto(moduleProto:Registered_protocol.T)=Proto.(compareenvironment_versionV7>=0)letno_filter(moduleProto:Registered_protocol.T)=ifis_recent_proto(moduleProto)thenRecent(moduleNo_filter(Proto))elseLegacy(moduleLegacy_mempool_plugin.No_filter(Proto))letfilter_table:filter_tProtocol_hash.Table.t=Protocol_hash.Table.create5letadd_to_filter_tableproto_hash(filter:filter_t)=assert(not(Protocol_hash.Table.memfilter_tableproto_hash));Protocol_hash.Table.addfilter_tableproto_hashfilterletregister_filter(moduleFilter:FILTER)=add_to_filter_tableFilter.Proto.hash(Recent(moduleFilter))letregister_legacy_filter(moduleFilter:Legacy_mempool_plugin.FILTER)=add_to_filter_tableFilter.Proto.hash(Legacy(moduleFilter))letfind_filter=Protocol_hash.Table.findfilter_table