123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 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. *)(* *)(*****************************************************************************)typeheader={block_hash:Block_hash.t;level:int32;predecessor:Block_hash.t;commitment_hash:Commitment.Hash.toption;previous_commitment_hash:Commitment.Hash.t;context:Smart_rollup_context_hash.t;inbox_witness:Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.t;inbox_hash:Inbox.Hash.t;}typecontent={inbox:Inbox.t;messages:stringlist;commitment:Commitment.toption;}type('header,'content)block={header:'header;content:'content;initial_tick:Z.t;num_ticks:int64;}typet=(header,unit)blocktypefull=(header,content)blockletcommitment_hash_opt_encoding=letopenData_encodinginletbinary=conv(Option.value~default:Commitment.Hash.zero)(funh->ifCommitment.Hash.(h=zero)thenNoneelseSomeh)Commitment.Hash.encodinginletjson=optionCommitment.Hash.encodinginsplitted~binary~jsonletheader_encoding=letopenData_encodinginconv(fun{block_hash;level;predecessor;commitment_hash;previous_commitment_hash;context;inbox_witness;inbox_hash;}->(block_hash,level,predecessor,commitment_hash,previous_commitment_hash,context,inbox_witness,inbox_hash))(fun(block_hash,level,predecessor,commitment_hash,previous_commitment_hash,context,inbox_witness,inbox_hash)->{block_hash;level;predecessor;commitment_hash;previous_commitment_hash;context;inbox_witness;inbox_hash;})@@obj8(req"block_hash"Block_hash.encoding~description:"Tezos block hash.")(req"level"int32~description:"Level of the block, corresponds to the level of the tezos block.")(req"predecessor"Block_hash.encoding~description:"Predecessor hash of the Tezos block.")(req"commitment_hash"commitment_hash_opt_encoding~description:"Hash of this block's commitment if any was computed for it.")(req"previous_commitment_hash"Commitment.Hash.encoding~description:"Previous commitment hash in the chain. If there is a commitment \
for this block, this field contains the commitment that was \
previously computed.")(req"context"Smart_rollup_context_hash.encoding~description:"Hash of the layer 2 context for this block.")(req"inbox_witness"Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.encoding~description:"Witness for the inbox for this block, i.e. the Merkle hash of \
payloads of messages.")(req"inbox_hash"Inbox.Hash.encoding~description:"Hash of the inbox for this block.")letheader_size=WithExceptions.Option.get~loc:__LOC__@@Data_encoding.Binary.fixed_lengthheader_encodingletcontent_encoding=letopenData_encodinginconv(fun{inbox;messages;commitment}->(inbox,messages,commitment))(fun(inbox,messages,commitment)->{inbox;messages;commitment})@@obj3(req"inbox"Inbox.encoding~description:"Inbox for this block.")(req"messages"(list(dynamic_size(Variable.string'Hex)))~description:"Messages added to the inbox in this block.")(opt"commitment"Commitment.encoding~description:"Commitment, if any is computed for this block.")letblock_encodingheader_encodingcontent_encoding=letopenData_encodinginconv(fun{header;content;initial_tick;num_ticks}->(header,(content,(initial_tick,num_ticks))))(fun(header,(content,(initial_tick,num_ticks)))->{header;content;initial_tick;num_ticks})@@merge_objsheader_encoding@@merge_objscontent_encoding@@obj2(req"initial_tick"Data_encoding.n~description:"Initial tick of the PVM at this block, i.e. before evaluation of \
the messages.")(req"num_ticks"int64~description:"Number of ticks produced by the evaluation of the messages in \
this block.")letencoding=block_encodingheader_encodingData_encoding.unitletfull_encoding=block_encodingheader_encodingcontent_encodingletmost_recent_commitment(header:header)=Option.valueheader.commitment_hash~default:header.previous_commitment_hashletfinal_tick{initial_tick;num_ticks;_}=Z.maxZ.zero(Z.addinitial_tick(Z.of_int64num_ticks))