123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2018 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. *)(* *)(*****************************************************************************)openEnvironment_context(* This module contains the real module signature of an economic
protocol that the Shell sees. There is actually only one signature
to avoid [if]-[then]-[else] expressions inside the Shell.
When we change the module signature output of the environment, we
need to implement a forward-compatible interface. This is done by
upgrading the old interface to the new one.
The first change in this signature was introduced by the [V3]
environment. This is why we implement a functor from the initial
environment [V0] to [V3] directly because neither [V1] nor [V2]
change the module signature output of the environment.
All the equalities constraints are here for typing only. We use a
destructive substitution ([:=]) for types that are defined by the
shell, or that are common to all the economic protocol
environments, and an equality constraint ([=]) for the types that
are abstracted from the economic protocol.
[module type T] defines the same signature as the last [Vx]
environment ([module type Vx_T]).
If you want to mock this module type, see {!Environment_protocol_T_test}. *)moduletypeT=Environment_protocol_T_V10.T(* Documentation for this interface may be found in
module type [PROTOCOL] of [sigs/v6/updater.mli]. *)moduleV0toV10(E:Environment_protocol_T_V0.Twithtypecontext:=Context.tandtypequota:=quotaandtypevalidation_result:=validation_resultandtyperpc_context:=rpc_contextandtypetztrace:=Error_monad.tztraceandtype'atzresult:='aError_monad.tzresult):Environment_protocol_T_V10.Twithtypecontext:=Context.tandtypequota:=quotaandtypevalidation_result:=validation_resultandtyperpc_context:=rpc_contextandtypetztrace:=Error_monad.tztraceandtype'atzresult:='aError_monad.tzresultandtypeblock_header_data=E.block_header_dataandtypeblock_header=E.block_headerandtypeblock_header_metadata=E.block_header_metadataandtypeoperation_data=E.operation_dataandtypeoperation=E.operationandtypeoperation_receipt=E.operation_receiptandtypevalidation_state=E.validation_stateandtypeapplication_state=E.validation_stateandtypecache_key=Context.Cache.keyandtypecache_value=Context.Cache.value=structincludeEletblock_header_metadata_encoding_with_legacy_attestation_name=block_header_metadata_encodingletoperation_data_encoding_with_legacy_attestation_name=operation_data_encodingletoperation_receipt_encoding_with_legacy_attestation_name=operation_receipt_encodingletoperation_data_and_receipt_encoding_with_legacy_attestation_name=operation_data_and_receipt_encodingtypeapplication_state=validation_statetypemode=|Applicationofblock_header|Partial_validationofblock_header|Constructionof{predecessor_hash:Tezos_crypto.Hashed.Block_hash.t;timestamp:Time.Protocol.t;block_header_data:block_header_data;}|Partial_constructionof{predecessor_hash:Tezos_crypto.Hashed.Block_hash.t;timestamp:Time.Protocol.t;}letbegin_validation_or_applicationvalidation_or_applicationctxtchain_idmode~(predecessor:Block_header.shell_header)=match(validation_or_application,mode)with|`Validation,Applicationblock_header|_,Partial_validationblock_header->(* For the validation of an existing block, we always use the
old [begin_partial_application], even in full [Application]
mode. Indeed, this maintains the behavior of old block
[precheck] (from [lib_validation/block_validation.ml]), which
relied on [Partial_validation] mode to quickly assess the
viability of the block. *)begin_partial_application~chain_id~ancestor_context:ctxt~predecessor_timestamp:predecessor.timestamp~predecessor_fitness:predecessor.fitnessblock_header|`Application,Applicationblock_header->begin_application~chain_id~predecessor_context:ctxt~predecessor_timestamp:predecessor.timestamp~predecessor_fitness:predecessor.fitnessblock_header|_,Construction{predecessor_hash;timestamp;block_header_data}->begin_construction~chain_id~predecessor_context:ctxt~predecessor_timestamp:predecessor.timestamp~predecessor_level:predecessor.level~predecessor_fitness:predecessor.fitness~predecessor:predecessor_hash~timestamp~protocol_data:block_header_data()|_,Partial_construction{predecessor_hash;timestamp}->begin_construction~chain_id~predecessor_context:ctxt~predecessor_timestamp:predecessor.timestamp~predecessor_level:predecessor.level~predecessor_fitness:predecessor.fitness~predecessor:predecessor_hash~timestamp()letbegin_validation=begin_validation_or_application`Validationletbegin_application=begin_validation_or_application`Applicationletvalidate_operation?check_signature:_validation_state_ophoperation=letopenLwt_result_syntaxinlet*validation_state,_operation_receipt=apply_operationvalidation_stateoperationinreturnvalidation_stateletapply_operationapplication_state_ophoperation=apply_operationapplication_stateoperationletfinalize_validationvalidation_state=letopenLwt_result_syntaxinlet*_=finalize_blockvalidation_stateinreturn_unitletfinalize_applicationapplication_state_shell_header=finalize_blockapplication_stateletcompare_operations(_,op)(_,op')=compare_operationsopop'letacceptable_passop=matchacceptable_passesopwith[n]->Somen|_->Noneletvalue_of_key~chain_id:_~predecessor_context:_~predecessor_timestamp:_~predecessor_level:_~predecessor_fitness:_~predecessor:_~timestamp:_=Lwt.return_ok(fun_->Lwt.return(Error_monad.error_with"element_of_key called on environment protocol < V3"))typecache_key=Context.Cache.keytypecache_value=Context.Cache.valueletinit_chain_idchd=initchd(* Fake mempool that can be successfully initialized but cannot
accept any operations. *)moduleMempool=structtypet=unittypevalidation_info=unittypeconflict_handler=existing_operation:Tezos_crypto.Hashed.Operation_hash.t*operation->new_operation:Tezos_crypto.Hashed.Operation_hash.t*operation->[`Keep|`Replace]typeoperation_conflict=|Operation_conflictof{existing:Tezos_crypto.Hashed.Operation_hash.t;new_operation:Tezos_crypto.Hashed.Operation_hash.t;}typeadd_result=|Added|Replacedof{removed:Tezos_crypto.Hashed.Operation_hash.t}|Unchangedtypeadd_error=|Validation_erroroferrortrace|Add_conflictofoperation_conflicttypemerge_error=|Incompatible_mempool|Merge_conflictofoperation_conflictletinit__~head_hash:_~head:_=Lwt.return_ok((),())letencoding=Data_encoding.unitletadd_operation?check_signature:_?conflict_handler:____=letmsg="The mempool cannot accept any operations because it does not support \
the current protocol."inLwt.return_error(Validation_error[Exn(Failuremsg)])letremove_operation()_=()letmerge?conflict_handler:_()()=Ok()letoperations()=Tezos_crypto.Hashed.Operation_hash.Map.emptyendend(* [module type PROTOCOL] is protocol signature that the shell can use.
A module of this signature is typically obtained through an adapter
(see Lift functors in environment definitions) of the Main module
(which complies with the [Updater] signature).
*)moduletypePROTOCOL=sigincludeTwithtypecontext:=Context.tandtypequota:=quotaandtypevalidation_result:=validation_resultandtyperpc_context:=rpc_contextandtypetztrace:=Error_monad.tztraceandtype'atzresult:='aError_monad.tzresultandtypecache_key:=Context.Cache.keyandtypecache_value:=Context.Cache.valuevalset_log_message_consumer:(Internal_event.level->string->unit)->unitvalenvironment_version:Protocol.env_versionvalexpected_context_hash:header_context_hash_semanticsvalbegin_validation:Context.t->Tezos_crypto.Hashed.Chain_id.t->mode->predecessor:Block_header.shell_header->cache:Context.source_of_cache->validation_stateError_monad.tzresultLwt.tvalbegin_application:Context.t->Tezos_crypto.Hashed.Chain_id.t->mode->predecessor:Block_header.shell_header->cache:Context.source_of_cache->application_stateError_monad.tzresultLwt.tmoduleMempool:sigincludemoduletypeofMempoolvalinit:Context.t->Tezos_crypto.Hashed.Chain_id.t->head_hash:Tezos_crypto.Hashed.Block_hash.t->head:Block_header.shell_header->cache:Context.source_of_cache->(validation_info*t)tzresultLwt.tendend(*
For environment V where V < V3, the caching mechanism is ignored.
The following functor provides a protocol adapter to implement
this.
*)moduleIgnoreCaches(P:Twithtypecontext:=Context.tandtypequota:=quotaandtypevalidation_result:=validation_resultandtyperpc_context:=rpc_contextandtypetztrace:=Error_monad.tztraceandtype'atzresult:='aError_monad.tzresult)=structincludePletinitchain_idcontextheader=letopenLwt_syntaxinlet*context=Context.Cache.set_cache_layoutcontext[]ininitchain_idcontextheaderletbegin_validationctxtchain_idmode~predecessor~cache:_=begin_validationctxtchain_idmode~predecessorletbegin_applicationctxtchain_idmode~predecessor~cache:_=begin_applicationctxtchain_idmode~predecessormoduleMempool=structincludeMempoolletinitctxtchain_id~head_hash~head~cache:_=initctxtchain_id~head_hash~headendend