123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)leterr_implementation_mismatch~expected~got=Format.kasprintfinvalid_arg"Context implementation mismatch: expecting %s, got %s"expectedgotopenContext_sigstype('repo,'tree)pvm_context_impl=(moduleContext_sigs.Swithtyperepo='repoandtypetree='tree)letequiv(a,b)(c,d)=(Equality_witness.eqac,Equality_witness.eqbd)typehash=Context_hash.ttype'at=|Context:{index:('a,'repo)index;pvm_context_impl:('repo,'tree)pvm_context_impl;impl_name:string;tree:'tree;equality_witness:('repo,'tree)equality_witness;}->'attypero=[`Read]ttyperw=[`Read|`Write]tletmake~index~tree~pvm_context_impl~equality_witness~impl_name=Context{index;tree;pvm_context_impl;equality_witness;impl_name}letload:typetreerepo.(repo,tree)pvm_context_impl->cache_size:int->'aStore_sigs.mode->string->'attzresultLwt.t=fun(modulePvm_Context_Impl)~cache_sizemodepath->letopenLwt_result_syntaxinlet*index=Pvm_Context_Impl.load~cache_sizemodepathinletequality_witness=Pvm_Context_Impl.equality_witnessinletimpl_name=Pvm_Context_Impl.impl_nameinreturn@@make~index~tree:(Pvm_Context_Impl.PVMState.empty())~pvm_context_impl:(modulePvm_Context_Impl)~equality_witness~impl_nameletindexc=cletclose(typea)(Context{pvm_context_impl=(modulePvm_Context_Impl);index;_}:at):unitLwt.t=Pvm_Context_Impl.closeindexletreadonly(typea)(Context({pvm_context_impl=(modulePvm_Context_Impl);index;_}aso):at):ro=Context{owithindex=Pvm_Context_Impl.readonlyindex}letcheckout(typea)(Context({pvm_context_impl=(modulePvm_Context_Impl);index;_}aso):at)hash:atoptionLwt.t=letopenLwt_syntaxinlet+ctx=Pvm_Context_Impl.checkoutindexhashinmatchctxwith|None->None|Some{index;tree}->Some(Context{owithindex;tree})letempty(typea)(Context({pvm_context_impl=(modulePvm_Context_Impl);index;_}aso):at):at=let{index;tree}=Pvm_Context_Impl.emptyindexinContext{owithindex;tree}letcommit?message(Context{pvm_context_impl=(modulePvm_Context_Impl);index;tree;_}:[>`Write]t)=Pvm_Context_Impl.commit?message{index;tree}letis_gc_finished(Context{pvm_context_impl=(modulePvm_Context_Impl);index;_}:[>`Write]t)=Pvm_Context_Impl.is_gc_finishedindexletsplit(typea)(Context{pvm_context_impl=(modulePvm_Context_Impl);index;_}:at)=Pvm_Context_Impl.splitindexletgc(Context{pvm_context_impl=(modulePvm_Context_Impl);index;_}:[>`Write]t)?callbackhash=Pvm_Context_Impl.gcindex?callbackhashletwait_gc_completion(Context{pvm_context_impl=(modulePvm_Context_Impl);index;_}:[>`Write]t)=Pvm_Context_Impl.wait_gc_completionindexletexport_snapshot(typea)(Context{pvm_context_impl=(modulePvm_Context_Impl);index;_}:at)=Pvm_Context_Impl.export_snapshotindextypepvmstate=|PVMState:{pvm_context_impl:('repo,'tree)pvm_context_impl;impl_name:string;pvmstate:'tree;equality_witness:('repo,'tree)equality_witness;}->pvmstateletmake_pvmstate~pvm_context_impl~equality_witness~impl_name~pvmstate=PVMState{pvm_context_impl;impl_name;pvmstate;equality_witness}(** State of the PVM that this rollup node deals with *)modulePVMState=structtypevalue=pvmstateletempty:typea.at->value=fun(Context{pvm_context_impl=(modulePvm_Context_Impl);equality_witness;impl_name;_;})->make_pvmstate~pvm_context_impl:(modulePvm_Context_Impl)~equality_witness~pvmstate:(Pvm_Context_Impl.PVMState.empty())~impl_nameletfind:typea.at->valueoptionLwt.t=fun(Context{pvm_context_impl=(modulePvm_Context_Impl);index;tree;equality_witness;impl_name;_;})->letopenLwt_syntaxinlet+pvmstate=Pvm_Context_Impl.PVMState.find{index;tree}inmatchpvmstatewith|None->None|Somepvmstate->Some(make_pvmstate~pvm_context_impl:(modulePvm_Context_Impl)~equality_witness~pvmstate~impl_name)letlookup:value->stringlist->bytesoptionLwt.t=fun(PVMState{pvm_context_impl=(modulePvm_Context_Impl);pvmstate;_})path->Pvm_Context_Impl.PVMState.lookuppvmstatepathletset:typea.at->value->atLwt.t=fun(Context({pvm_context_impl=(modulePvm_Context_Impl);index;tree;_}aso1))(PVMStateo2)->letopenLwt_syntaxinmatchequivo1.equality_witnesso2.equality_witnesswith|SomeRefl,SomeRefl->let+ctxt=Pvm_Context_Impl.PVMState.set{index;tree}o2.pvmstateinContext{o1withindex=ctxt.index;tree=ctxt.tree}|_->err_implementation_mismatch~expected:o1.impl_name~got:o2.impl_nameendmoduleInternal_for_tests=structletget_a_tree:(moduleContext_sigs.S)->string->pvmstateLwt.t=fun(modulePvm_Context_Impl)key->letopenLwt_syntaxinlet+tree=Pvm_Context_Impl.Internal_for_tests.get_a_treekeyinmake_pvmstate~pvm_context_impl:(modulePvm_Context_Impl)~equality_witness:Pvm_Context_Impl.equality_witness~impl_name:Pvm_Context_Impl.impl_name~pvmstate:treeendmoduleVersion=structtypet=V0letversion=V0letencoding=letopenData_encodinginconv_with_guard(funV0->0)(function|0->OkV0|v->Error("Unsupported context version "^string_of_intv))int31letcheck=functionV0->Result.return_unitletto_string=functionV0->"0"end