123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 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. *)(* *)(*****************************************************************************)(* Backend-agnostic operations on the context *)moduleEnvironment_context=Tezos_protocol_environment.ContextmoduleMemory_context=Tezos_protocol_environment.Memory_contextleterr_implementation_mismatch=Tezos_protocol_environment.err_implementation_mismatch(** Values of type [index] are used to [checkout] contexts specified by their hash. *)typeindex=|Disk_indexofContext.index|Memory_indexofTezos_context_memory.Context.indexletindex(context:Environment_context.t)=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Disk_index(Context.indexctxt)|Context{kind=Memory_context.Context;ctxt;_}->Memory_index(Tezos_context_memory.Context.indexctxt)|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletmem(context:Environment_context.t)key=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.memctxtkey|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.memctxtkey|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletmem_tree(context:Environment_context.t)key=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.mem_treectxtkey|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.mem_treectxtkey|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletfind(context:Environment_context.t)key=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.findctxtkey|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.findctxtkey|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletadd(context:Environment_context.t)keydata=letopenLwt_syntaxinmatchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->let+ctxt=Context.addctxtkeydatainShell_context.wrap_disk_contextctxt|Context{kind=Memory_context.Context;ctxt;_}->let+ctxt=Tezos_context_memory.Context.addctxtkeydatainMemory_context.wrap_memory_contextctxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletfold_value?depth(context:Environment_context.t)key~order~init~f=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.fold?depthctxtkey~order~init~f:(funktreeacc->letv()=Context.Tree.to_valuetreeinfkvacc)|Context{kind=Memory_context.Context;ctxt;_}->letopenTezos_context_memoryinContext.fold?depthctxtkey~order~init~f:(funktreeacc->letv()=Context.Tree.to_valuetreeinfkvacc)|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletadd_protocol(context:Environment_context.t)proto_hash=letopenLwt_syntaxinmatchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->let+ctxt=Context.add_protocolctxtproto_hashinShell_context.wrap_disk_contextctxt|Context{kind=Memory_context.Context;ctxt;_}->let+ctxt=Tezos_context_memory.Context.add_protocolctxtproto_hashinMemory_context.wrap_memory_contextctxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletget_protocol(context:Environment_context.t)=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.get_protocolctxt|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.get_protocolctxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletadd_predecessor_block_metadata_hash(context:Environment_context.t)hash=letopenLwt_syntaxinmatchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->let+ctxt=Context.add_predecessor_block_metadata_hashctxthashinShell_context.wrap_disk_contextctxt|Context{kind=Memory_context.Context;ctxt;_}->let+ctxt=Tezos_context_memory.Context.add_predecessor_block_metadata_hashctxthashinMemory_context.wrap_memory_contextctxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletadd_predecessor_ops_metadata_hash(context:Environment_context.t)hash=letopenLwt_syntaxinmatchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->let+ctxt=Context.add_predecessor_ops_metadata_hashctxthashinShell_context.wrap_disk_contextctxt|Context{kind=Memory_context.Context;ctxt;_}->let+ctxt=Tezos_context_memory.Context.add_predecessor_ops_metadata_hashctxthashinMemory_context.wrap_memory_contextctxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_namelethash~time?message(context:Environment_context.t)=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.hash~time?messagectxt|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.hash~time?messagectxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletget_test_chain(context:Environment_context.t)=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.get_test_chainctxt|Context{kind=Memory_context.Context;_}->Lwt.returnTest_chain_status.Not_running|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletadd_test_chain(context:Environment_context.t)status=letopenLwt_syntaxinmatchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->let+ctxt=Context.add_test_chainctxtstatusinShell_context.wrap_disk_contextctxt|Context{kind=Memory_context.Context;ctxt;_}->let+ctxt=Tezos_context_memory.Context.add_test_chainctxtstatusinMemory_context.wrap_memory_contextctxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletfork_test_chain(context:Environment_context.t)~protocol~expiration=letopenLwt_syntaxinmatchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->let+ctxt=Context.fork_test_chainctxt~protocol~expirationinShell_context.wrap_disk_contextctxt|Context{kind=Memory_context.Context;ctxt;_}->let+ctxt=Tezos_context_memory.Context.fork_test_chainctxt~protocol~expirationinMemory_context.wrap_memory_contextctxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletcommit~time?message(context:Environment_context.t)=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.commit~time?messagectxt|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.commit~time?messagectxt|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletgccontext_indexcontext_hash=matchcontext_indexwith|Disk_indexindex->Context.gcindexcontext_hash|Memory_indexindex->Tezos_context_memory.Context.gcindexcontext_hashletwait_gc_completioncontext_index=matchcontext_indexwith|Disk_indexindex->Context.wait_gc_completionindex|Memory_indexindex->Tezos_context_memory.Context.wait_gc_completionindexletis_gc_allowedcontext_index=matchcontext_indexwith|Disk_indexindex->Context.is_gc_allowedindex|Memory_indexindex->Tezos_context_memory.Context.is_gc_allowedindexletsplitcontext_index=matchcontext_indexwith|Disk_indexindex->Context.splitindex|Memory_indexindex->Tezos_context_memory.Context.splitindexletsync=function|Disk_indexindex->Context.syncindex|Memory_indexindex->Tezos_context_memory.Context.syncindexletcommit_test_chain_genesis(context:Environment_context.t)block_header=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.commit_test_chain_genesisctxtblock_header|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.commit_test_chain_genesisctxtblock_header|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletcompute_testchain_genesis(context:Environment_context.t)block_hash=matchcontextwith|Context{kind=Shell_context.Context;_}->Context.compute_testchain_genesisblock_hash|Context{kind=Memory_context.Context;_}->Tezos_context_memory.Context.compute_testchain_genesisblock_hash|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletmerkle_tree(context:Environment_context.t)leaf_kindpath=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.merkle_treectxtleaf_kindpath|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.merkle_treectxtleaf_kindpath|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletmerkle_tree_v2(context:Environment_context.t)leaf_kindpath=matchcontextwith|Context{kind=Shell_context.Context;ctxt;_}->Context.merkle_tree_v2ctxtleaf_kindpath|Context{kind=Memory_context.Context;ctxt;_}->Tezos_context_memory.Context.merkle_tree_v2ctxtleaf_kindpath|Contextt->err_implementation_mismatch~expected:"shell or memory"~got:t.impl_nameletcommit_genesiscontext_index~chain_id~time~protocol=matchcontext_indexwith|Disk_indexindex->Context.commit_genesisindex~chain_id~time~protocol|Memory_indexindex->Tezos_context_memory.Context.commit_genesisindex~chain_id~time~protocolletcheckoutcontext_indexcontext_hash=letopenLwt_syntaxinmatchcontext_indexwith|Disk_indexindex->let+ctxt=Context.checkoutindexcontext_hashinOption.mapShell_context.wrap_disk_contextctxt|Memory_indexindex->let+ctxt=Tezos_context_memory.Context.checkoutindexcontext_hashinOption.mapMemory_context.wrap_memory_contextctxtletcheckout_exncontext_indexcontext_hash=letopenLwt_syntaxinmatchcontext_indexwith|Disk_indexindex->let+ctxt=Context.checkout_exnindexcontext_hashinShell_context.wrap_disk_contextctxt|Memory_indexindex->let+ctxt=Tezos_context_memory.Context.checkout_exnindexcontext_hashinMemory_context.wrap_memory_contextctxtletexistscontext_indexcontext_hash=matchcontext_indexwith|Disk_indexindex->Context.existsindexcontext_hash|Memory_indexindex->Tezos_context_memory.Context.existsindexcontext_hashletclosecontext_index=matchcontext_indexwith|Disk_indexindex->Context.closeindex|Memory_indexindex->Tezos_context_memory.Context.closeindex