123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)moduletypeT=sigincludeRegistered_protocol.TmodulePlugin:sigtypeconfigvalconfig_encoding:configData_encoding.tvaldefault_config:configtypeinfovalinit:Tezos_protocol_environment.Context.t->head:Tezos_base.Block_header.shell_header->infotzresultLwt.tvalflush:info->head:Tezos_base.Block_header.shell_header->infotzresultLwt.tvalsyntactic_check:operation->[`Well_formed|`Ill_formed]Lwt.tvalpre_filter:info->config->operation->[`Passed_prefilterof[`High|`Medium|`LowofQ.tlist]|`Branch_delayedoftztrace|`Branch_refusedoftztrace|`Refusedoftztrace|`Outdatedoftztrace]Lwt.tvalconflict_handler:config->Mempool.conflict_handlermoduleConflict_map:sigtypetvalempty:tvalupdate:t->new_operation:operation->replacements:operationlist->tvalfee_needed_to_replace_by_fee:config->candidate_op:operation->conflict_map:t->int64optionendvalfee_needed_to_overtake:op_to_overtake:operation->candidate_op:operation->int64optionendendmoduletypeRPC=sigmoduleProto:Registered_protocol.Tvalrpc_services:Tezos_protocol_environment.rpc_contextTezos_rpc.Directory.directoryendmoduleNo_plugin(Proto:Registered_protocol.T):Twithtypeoperation_data=Proto.operation_dataandtypeoperation=Proto.operationandtypeMempool.t=Proto.Mempool.tandtypePlugin.info=unit=structincludeProtomodulePlugin=structtypeconfig=unitletconfig_encoding=Data_encoding.emptyletdefault_config=()typeinfo=unitletinit_~head:_=Lwt_result_syntax.return_unitletflush_~head:_=Lwt_result_syntax.return_unitletsyntactic_check_=Lwt.return`Well_formedletpre_filter___=Lwt.return@@`Passed_prefilter(`Low[])letconflict_handler_~existing_operation~new_operation=ifcompare_operationsexisting_operationnew_operation<0then`Replaceelse`KeepmoduleConflict_map=structtypet=unitletempty=()letupdate_t~new_operation:_~replacements:_=()letfee_needed_to_replace_by_fee_config~candidate_op:_~conflict_map:_=Noneendletfee_needed_to_overtake~op_to_overtake:_~candidate_op:_=NoneendendmoduletypeMETRICS=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)letvalidation_plugin_table:(moduleT)Protocol_hash.Table.t=Protocol_hash.Table.create5letadd_to_validation_plugin_tableproto_hashproto_with_plugin=assert(not(Protocol_hash.Table.memvalidation_plugin_tableproto_hash));Protocol_hash.Table.addvalidation_plugin_tableproto_hashproto_with_pluginletregister_validation_plugin(moduleProto_with_plugin:T)=add_to_validation_plugin_tableProto_with_plugin.hash(moduleProto_with_plugin)letvalidation_plugin_not_found=Internal_event.Simple.declare_1~section:["block";"validation"]~name:"validation_plugin_not_found"~msg:"no validation plugin found for protocol {protocol_hash}"~level:Warning~pp1:Protocol_hash.pp("protocol_hash",Protocol_hash.encoding)typeerror+=Ill_formed_operationofOperation_hash.tlet()=register_error_kind`Permanent~id:"validation.plugin.ill_formed_operation"~title:"Ill_formed_operation"~description:"Ill-formed operation filtered"~pp:(funppfoph->Format.fprintfppf"Ill-formed operation filtered: %a."Operation_hash.ppoph)Data_encoding.(obj1(req"operation_hash"Operation_hash.encoding))(functionIll_formed_operationoph->Someoph|_->None)(funoph->Ill_formed_operationoph)modulePatch_T(Proto:T):T=structincludeProtoletvalidate_operation?check_signaturevalidation_stateophop=letopenLwt_syntaxinlet*status=Proto.Plugin.syntactic_checkopinmatchstatuswith|`Ill_formed->Lwt_result_syntax.tzfail(Ill_formed_operationoph)|`Well_formed->Proto.validate_operation?check_signaturevalidation_stateophopmoduleMempool=structincludeProto.Mempoolletadd_operation?check_signature?conflict_handlervalidation_infomempool_state(oph,op)=letopenLwt_syntaxinlet*status=Proto.Plugin.syntactic_checkopinmatchstatuswith|`Ill_formed->Lwt.return_error(Proto.Mempool.Validation_error(TzTrace.make(Ill_formed_operationoph)))|`Well_formed->Proto.Mempool.add_operation?check_signature?conflict_handlervalidation_infomempool_state(oph,op)endendletproto_with_validation_plugin~block_hashprotocol_hash=letopenLwt_result_syntaxinlet*(moduleProto_with_plugin)=matchProtocol_hash.Table.findvalidation_plugin_tableprotocol_hashwith|Someproto_with_plugin->returnproto_with_plugin|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.(emitvalidation_plugin_not_found)protocol_hashinreturn(moduleNo_plugin(Proto):T))inreturn(modulePatch_T(Proto_with_plugin):T)