Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file sc_rollup_commitment_storage.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 TriliTech <contact@trili.tech> *)(* *)(* 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. *)(* *)(*****************************************************************************)openSc_rollup_errorsmoduleStore=Storage.Sc_rollupmoduleCommitment=Sc_rollup_commitment_reprmoduleCommitment_hash=Commitment.Hashletget_commitment_opt_unsafectxtrollupcommitment=letopenLwt_result_syntaxinlet*ctxt,res=Store.Commitments.find(ctxt,rollup)commitmentinreturn(res,ctxt)letget_commitment_unsafectxtrollupcommitment=letopenLwt_tzresult_syntaxinlet*res,ctxt=get_commitment_opt_unsafectxtrollupcommitmentinmatchreswith|None->fail(Sc_rollup_unknown_commitmentcommitment)|Somecommitment->return(commitment,ctxt)letlast_cemented_commitmentctxtrollup=letopenLwt_tzresult_syntaxinlet*ctxt,res=Store.Last_cemented_commitment.findctxtrollupinmatchreswith|None->fail(Sc_rollup_does_not_existrollup)|Somelcc->return(lcc,ctxt)letget_commitmentctxtrollupcommitment=letopenLwt_tzresult_syntaxin(* Assert that a last cemented commitment exists. *)let*_lcc,ctxt=last_cemented_commitmentctxtrollupinget_commitment_unsafectxtrollupcommitmentletlast_cemented_commitment_hash_with_levelctxtrollup=letopenLwt_tzresult_syntaxinlet*commitment_hash,ctxt=last_cemented_commitmentctxtrollupinlet+{inbox_level;_},ctxt=get_commitment_unsafectxtrollupcommitment_hashin(commitment_hash,inbox_level,ctxt)letset_commitment_addedctxtrollupnodenew_value=letopenLwt_tzresult_syntaxinlet*ctxt,res=Store.Commitment_added.find(ctxt,rollup)nodeinmatchreswith|Someold_value->(* No need to re-add the read value *)return(0,old_value,ctxt)|None->let*ctxt,size_diff,_was_bound=Store.Commitment_added.add(ctxt,rollup)nodenew_valueinreturn(size_diff,new_value,ctxt)letget_predecessor_opt_unsafectxtrollupnode=letopenLwt_result_syntaxinlet*commitment,ctxt=get_commitment_opt_unsafectxtrollupnodeinreturn(Option.map(fun(c:Commitment.t)->c.predecessor)commitment,ctxt)letget_predecessor_unsafectxtrollupnode=letopenLwt_tzresult_syntaxinlet*commitment,ctxt=get_commitment_unsafectxtrollupnodeinreturn(commitment.predecessor,ctxt)lethashctxtcommitment=letopenTzresult_syntaxinlet*ctxt=Raw_context.consume_gasctxtSc_rollup_costs.Constants.cost_serialize_commitmentinletcommitment_bytes_opt=Data_encoding.Binary.to_bytes_optSc_rollup_commitment_repr.encodingcommitmentinlet*commitment_bytes=Option.to_result~none:(trace_of_errorSc_rollup_bad_commitment_serialization)commitment_bytes_optinletbytes_len=Bytes.lengthcommitment_bytesinlet*ctxt=Raw_context.consume_gasctxt(Sc_rollup_costs.cost_hash_bytes~bytes_len)inreturn(ctxt,Sc_rollup_commitment_repr.Hash.hash_bytes[commitment_bytes])moduleInternal_for_tests=structletget_cemented_commitments_with_levelsctxtrollup=letopenLwt_tzresult_syntaxinletrecauxctxtcommitments_with_levelscommitment_hash=let*commitment_opt,ctxt=get_commitment_opt_unsafectxtrollupcommitment_hashinmatchcommitment_optwith|None->return(commitments_with_levels,ctxt)|Some{predecessor;inbox_level;_}->(aux[@ocaml.tailcall])ctxt((commitment_hash,inbox_level)::commitments_with_levels)predecessorinlet*lcc_hash,ctxt=last_cemented_commitmentctxtrollupinlet+commitments_with_levels,ctxt=auxctxt[]lcc_hashin(commitments_with_levels,ctxt)end