123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.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. *)(* *)(*****************************************************************************)letmax_block_length=100letmax_operation_data_length=0letvalidation_passes=[]letacceptable_pass_op=Nonetypeblock_header_data=stringletblock_header_data_encoding=Data_encoding.(obj1(req"block_header_data"(stringPlain)))typeblock_header={shell:Block_header.shell_header;protocol_data:block_header_data;}typeblock_header_metadata=unitletblock_header_metadata_encoding=Data_encoding.unittypeoperation_data=unitletoperation_data_encoding=Data_encoding.unittypeoperation_receipt=unitletoperation_receipt_encoding=Data_encoding.unitletoperation_data_and_receipt_encoding=Data_encoding.conv(function((),())->())(fun()->((),()))Data_encoding.unittypeoperation={shell:Operation.shell_header;protocol_data:operation_data;}letcompare_operations__=0typevalidation_state={context:Context.t;fitness:Fitness.t}typeapplication_state=validation_statetypemode=|Applicationofblock_header|Partial_validationofblock_header|Constructionof{predecessor_hash:Block_hash.t;timestamp:Time.t;block_header_data:block_header_data;}|Partial_constructionof{predecessor_hash:Block_hash.t;timestamp:Time.t;}(* Same as genesis *)letfitness_from_levellevel=letversion_number="\002"inletint32_to_bytesi=letb=Bytes.make4'\000'inTzEndian.set_int32b0i;bin[Bytes.of_stringversion_number;int32_to_byteslevel;Bytes.empty;int32_to_bytes(-1l);int32_to_bytes0l;]letbegin_validationcontext_chain_idmode~(predecessor:Block_header.shell_header)=letfitness=matchmodewith|Applicationblock_header|Partial_validationblock_header->block_header.shell.fitness|Construction_|Partial_construction_->fitness_from_levelInt32.(succpredecessor.level)inreturn{context;fitness}letbegin_application=begin_validationtypeerror+=No_errorlet()=register_error_kind`Permanent~id:"no-error"~title:"No error"~description:"There is no error, this is a no-op protocol"~pp:(funppf()->Format.fprintfppf"@[<h 0>No error in no-op protocol@]")Data_encoding.unit(functionNo_error->Some()|_->None)(fun()->No_error)letvalidate_operation?check_signature:__state_oph_op=tzfailNo_errorletapply_operation_state_oph_op=tzfailNo_errorletfinalize_validation_state=return_unitletfinalize_applicationapplication_state_shell_header=return({Updater.message=None;context=application_state.context;fitness=application_state.fitness;max_operations_ttl=0;last_allowed_fork_level=0l;},())letinit_chain_idcontextblock_header=letopenBlock_headerinletfitness=block_header.fitnessinContext.Cache.set_cache_layoutcontext[]>>=funcontext->return{Updater.message=None;context;fitness;max_operations_ttl=0;last_allowed_fork_level=0l;}letvalue_of_key~chain_id:_~predecessor_context:_~predecessor_timestamp:_~predecessor_level:_~predecessor_fitness:_~predecessor:_~timestamp:_=return(fun_->tzfailNo_error)letrpc_services=RPC_directory.empty(* Fake mempool *)moduleMempool=structtypet=unittypevalidation_info=unittypeconflict_handler=existing_operation:Operation_hash.t*operation->new_operation:Operation_hash.t*operation->[`Keep|`Replace]typeoperation_conflict=|Operation_conflictof{existing:Operation_hash.t;new_operation:Operation_hash.t;}typeadd_result=|Added|Replacedof{removed: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:____=Lwt.return_ok((),Unchanged)letremove_operation()_=()letmerge?conflict_handler:_()()=Ok()letoperations()=Operation_hash.Map.emptyend