123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2018-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. *)(* *)(*****************************************************************************)typeblock_error=|Cannot_parse_operationofOperation_hash.t|Invalid_fitnessof{expected:Fitness.t;found:Fitness.t}|Non_increasing_timestamp|Non_increasing_fitness|Invalid_levelof{expected:Int32.t;found:Int32.t}|Invalid_proto_levelof{expected:int;found:int}|Replayed_operationofOperation_hash.t|Outdated_operationof{operation:Operation_hash.t;originating_block:Block_hash.t;}|Expired_chainof{chain_id:Chain_id.t;expiration:Time.Protocol.t;timestamp:Time.Protocol.t;}|Unexpected_number_of_validation_passesofint(* uint8 *)|Too_many_operationsof{pass:int;found:int;max:int}|Oversized_operationof{operation:Operation_hash.t;size:int;max:int}|Unallowed_passof{operation:Operation_hash.t;pass:int;allowed_pass:intoption;}|Cannot_parse_block_header|Economic_protocol_error|Invalid_protocol_environment_transitionofProtocol.env_version*Protocol.env_versionletblock_error_encoding=letopenData_encodinginunion[case(Tag0)~title:"Cannot_parse_operation"(obj2(req"error"(constant"cannot_parse_operation"))(req"operation"Operation_hash.encoding))(function|Cannot_parse_operationoperation->Some((),operation)|_->None)(fun((),operation)->Cannot_parse_operationoperation);case(Tag1)~title:"Invalid_fitness"(obj3(req"error"(constant"invalid_fitness"))(req"expected"Fitness.encoding)(req"found"Fitness.encoding))(function|Invalid_fitness{expected;found}->Some((),expected,found)|_->None)(fun((),expected,found)->Invalid_fitness{expected;found});case(Tag2)~title:"Non_increasing_timestamp"(obj1(req"error"(constant"non_increasing_timestamp")))(functionNon_increasing_timestamp->Some()|_->None)(fun()->Non_increasing_timestamp);case(Tag3)~title:"Non_increasing_fitness"(obj1(req"error"(constant"non_increasing_fitness")))(functionNon_increasing_fitness->Some()|_->None)(fun()->Non_increasing_fitness);case(Tag4)~title:"Invalid_level"(obj3(req"error"(constant"invalid_level"))(req"expected"int32)(req"found"int32))(function|Invalid_level{expected;found}->Some((),expected,found)|_->None)(fun((),expected,found)->Invalid_level{expected;found});case(Tag5)~title:"Invalid_proto_level"(obj3(req"error"(constant"invalid_proto_level"))(req"expected"uint8)(req"found"uint8))(function|Invalid_proto_level{expected;found}->Some((),expected,found)|_->None)(fun((),expected,found)->Invalid_proto_level{expected;found});case(Tag6)~title:"Replayed_operation"(obj2(req"error"(constant"replayed_operation"))(req"operation"Operation_hash.encoding))(function|Replayed_operationoperation->Some((),operation)|_->None)(fun((),operation)->Replayed_operationoperation);case(Tag7)~title:"Outdated_operation"(obj3(req"error"(constant"outdated_operation"))(req"operation"Operation_hash.encoding)(req"originating_block"Block_hash.encoding))(function|Outdated_operation{operation;originating_block}->Some((),operation,originating_block)|_->None)(fun((),operation,originating_block)->Outdated_operation{operation;originating_block});case(Tag8)~title:"Expired_chain"(obj4(req"error"(constant"expired_chain"))(req"chain_id"Chain_id.encoding)(req"expiration"Time.Protocol.encoding)(req"timestamp"Time.Protocol.encoding))(function|Expired_chain{chain_id;expiration;timestamp}->Some((),chain_id,expiration,timestamp)|_->None)(fun((),chain_id,expiration,timestamp)->Expired_chain{chain_id;expiration;timestamp});case(Tag9)~title:"Unexpected_number_of_validation_passes"(obj2(req"error"(constant"unexpected_number_of_passes"))(req"found"uint8))(function|Unexpected_number_of_validation_passesn->Some((),n)|_->None)(fun((),n)->Unexpected_number_of_validation_passesn);case(Tag10)~title:"Too_many_operations"(obj4(req"error"(constant"too_many_operations"))(req"validation_pass"uint8)(req"found"uint16)(req"max"uint16))(function|Too_many_operations{pass;found;max}->Some((),pass,found,max)|_->None)(fun((),pass,found,max)->Too_many_operations{pass;found;max});case(Tag11)~title:"Oversized_operation"(obj4(req"error"(constant"oversized_operation"))(req"operation"Operation_hash.encoding)(req"found"int31)(req"max"int31))(function|Oversized_operation{operation;size;max}->Some((),operation,size,max)|_->None)(fun((),operation,size,max)->Oversized_operation{operation;size;max});case(Tag12)~title:"Unallowed_pass"(obj4(req"error"(constant"invalid_pass"))(req"operation"Operation_hash.encoding)(req"pass"uint8)(req"allowed_pass"(optionuint8)))(function|Unallowed_pass{operation;pass;allowed_pass}->Some((),operation,pass,allowed_pass)|_->None)(fun((),operation,pass,allowed_pass)->Unallowed_pass{operation;pass;allowed_pass});case(Tag13)~title:"Cannot_parse_block_header"(obj1(req"error"(constant"cannot_parse_bock_header")))(functionCannot_parse_block_header->Some()|_->None)(fun()->Cannot_parse_block_header);case(Tag14)~title:"Economic_protocol_error"(obj1(req"error"(constant"economic_protocol_error")))(functionEconomic_protocol_error->Some()|_->None)(fun()->Economic_protocol_error);case(Tag15)~title:"Invalid_protocol_environment_transition"(obj3(req"error"(constant"invalid_protocol_environment_transition"))(req"before"Protocol.env_version_encoding)(req"after"Protocol.env_version_encoding))(function|Invalid_protocol_environment_transition(before,after)->Some((),before,after)|_->None)(fun((),before,after)->Invalid_protocol_environment_transition(before,after));]letpp_block_errorppf=function|Cannot_parse_operationoph->Format.fprintfppf"Failed to parse the operation %a."Operation_hash.pp_shortoph|Invalid_fitness{expected;found}->Format.fprintfppf"@[<v 2>Invalid fitness:@ expected %a@ found %a@]"Fitness.ppexpectedFitness.ppfound|Non_increasing_timestamp->Format.fprintfppf"Non increasing timestamp"|Non_increasing_fitness->Format.fprintfppf"Non increasing fitness"|Invalid_level{expected;found}->Format.fprintfppf"Invalid level:@ expected %ld@ found %ld"expectedfound|Invalid_proto_level{expected;found}->Format.fprintfppf"Invalid protocol level:@ expected %d@ found %d"expectedfound|Replayed_operationoph->Format.fprintfppf"The operation %a was previously included in the chain."Operation_hash.pp_shortoph|Outdated_operation{operation;originating_block}->Format.fprintfppf"The operation %a is outdated (originated in block: %a)"Operation_hash.pp_shortoperationBlock_hash.pp_shortoriginating_block|Expired_chain{chain_id;expiration;timestamp}->Format.fprintfppf"The block timestamp (%a) is later than its chain expiration date: %a \
(chain: %a)."Time.System.pp_hum(Time.System.of_protocol_exntimestamp)Time.System.pp_hum(Time.System.of_protocol_exnexpiration)Chain_id.pp_shortchain_id|Unexpected_number_of_validation_passesn->Format.fprintfppf"Invalid number of validation passes (found: %d)"n|Too_many_operations{pass;found;max}->Format.fprintfppf"Too many operations in validation pass %d (found: %d, max: %d)"passfoundmax|Oversized_operation{operation;size;max}->Format.fprintfppf"Oversized operation %a (size: %d, max: %d)"Operation_hash.pp_shortoperationsizemax|Unallowed_pass{operation;pass;allowed_pass}->Format.fprintfppf"Operation %a included in validation pass %d, while only the \
following passes are allowed: @[<h>%a@]"Operation_hash.pp_shortoperationpass(funfmt->function|None->Format.fprintffmt"None"|Somei->Format.pp_print_intfmti)allowed_pass|Cannot_parse_block_header->Format.fprintfppf"Failed to parse the block header."|Economic_protocol_error->Format.fprintfppf"Failed to validate the economic-protocol content of the block. More \
details in the trace."|Invalid_protocol_environment_transition(before,after)->Format.fprintfppf"Transition from protocol environment version %s to %s is not allowed."(Protocol.module_name_of_env_versionbefore)(Protocol.module_name_of_env_versionafter)typevalidation_process_error=|Missing_handshake|Inconsistent_handshakeofstring|Protocol_dynlink_failureofstring|Socket_path_too_longofstring|Socket_path_wrong_permissionofstring|Cannot_run_external_validatorofstringletvalidation_process_error_encoding=letopenData_encodinginunion[case(Tag0)~title:"Missing_handshake"(obj1(req"constant"(constant"missing_handshake")))(functionMissing_handshake->Some()|_->None)(fun()->Missing_handshake);case(Tag1)~title:"Inconsistent_handshake"(obj1(req"inconsistent_handshake"string))(functionInconsistent_handshakemsg->Somemsg|_->None)(funmsg->Inconsistent_handshakemsg);case(Tag2)~title:"Protocol_dynlink_failure"(obj1(req"protocol_dynlink_failure"string))(functionProtocol_dynlink_failuremsg->Somemsg|_->None)(funmsg->Protocol_dynlink_failuremsg);case(Tag3)~title:"Socket_path_too_long"(obj1(req"path"string))(functionSocket_path_too_longpath->Somepath|_->None)(funpath->Socket_path_too_longpath);case(Tag4)~title:"Socket_path_wrong_permission"(obj1(req"path"string))(functionSocket_path_wrong_permissionpath->Somepath|_->None)(funpath->Socket_path_wrong_permissionpath);case(Tag5)~title:"Cannot_run_external_validator"(obj1(req"msg"string))(functionCannot_run_external_validatormsg->Somemsg|_->None)(funmsg->Cannot_run_external_validatormsg);]letpp_validation_process_errorppf=function|Missing_handshake->Format.fprintfppf"Missing handshake while initializing validation process."|Protocol_dynlink_failuremsg->Format.fprintfppf"%s"msg|Inconsistent_handshakemsg->Format.fprintfppf"Inconsistent handshake: %s."msg|Socket_path_too_longpath->Format.fprintfppf"The socket path %s is too long. Please set an alternative path using \
XDG_RUNTIME_DIR to specify where to create the file"path|Socket_path_wrong_permissionpath->Format.fprintfppf"The socket path %s has wrong permissions. Please set an alternative \
path using XDG_RUNTIME_DIR to specify where to create the file"path|Cannot_run_external_validatormsg->Format.fprintfppf"Failed to run the external block validator process: %s"msgtypeerror+=|Invalid_blockof{block:Block_hash.t;error:block_error}|Unavailable_protocolof{block:Block_hash.t;protocol:Protocol_hash.t}|Inconsistent_operations_hashof{block:Block_hash.t;expected:Operation_list_list_hash.t;found:Operation_list_list_hash.t;}|Applying_non_validated_blockofBlock_hash.t|Failed_to_checkout_contextofContext_hash.t|System_errorof{errno:string;fn:string;msg:string}|Missing_test_protocolofProtocol_hash.t|Validation_process_failedofvalidation_process_error|Cannot_validate_while_shutting_downlet()=Error_monad.register_error_kind`Permanent~id:"validator.invalid_block"~title:"Invalid block"~description:"Invalid block."~pp:(funppf(block,error)->Format.fprintfppf"@[<v 2>Invalid block %a@ %a@]"Block_hash.pp_shortblockpp_block_errorerror)Data_encoding.(obj2(req"invalid_block"Block_hash.encoding)(req"error"block_error_encoding))(functionInvalid_block{block;error}->Some(block,error)|_->None)(fun(block,error)->Invalid_block{block;error});Error_monad.register_error_kind`Temporary~id:"validator.unavailable_protocol"~title:"Missing protocol"~description:"The protocol required for validating a block is missing."~pp:(funppf(block,protocol)->Format.fprintfppf"Missing protocol (%a) when validating the block %a."Protocol_hash.pp_shortprotocolBlock_hash.pp_shortblock)Data_encoding.(obj2(req"block"Block_hash.encoding)(req"missing_protocol"Protocol_hash.encoding))(function|Unavailable_protocol{block;protocol}->Some(block,protocol)|_->None)(fun(block,protocol)->Unavailable_protocol{block;protocol});Error_monad.register_error_kind`Temporary~id:"validator.inconsistent_operations_hash"~title:"Invalid merkle tree"~description:"The provided list of operations is inconsistent with the block header."~pp:(funppf(block,expected,found)->Format.fprintfppf"@[<v 2>The provided list of operations for block %a is inconsistent \
with the block header@ expected: %a@ found: %a@]"Block_hash.pp_shortblockOperation_list_list_hash.pp_shortexpectedOperation_list_list_hash.pp_shortfound)Data_encoding.(obj3(req"block"Block_hash.encoding)(req"expected"Operation_list_list_hash.encoding)(req"found"Operation_list_list_hash.encoding))(function|Inconsistent_operations_hash{block;expected;found}->Some(block,expected,found)|_->None)(fun(block,expected,found)->Inconsistent_operations_hash{block;expected;found});Error_monad.register_error_kind`Permanent~id:"Block_validator_process.applying_non_validated_block"~title:"Applying non validated block"~description:"Applying non validated block"~pp:(funppf(hash:Block_hash.t)->Format.fprintfppf"Applying non validated block %a"Block_hash.pp_shorthash)Data_encoding.(obj1(req"hash"Block_hash.encoding))(functionApplying_non_validated_blockbh->Somebh|_->None)(funbh->Applying_non_validated_blockbh);Error_monad.register_error_kind`Permanent~id:"Block_validator_process.failed_to_checkout_context"~title:"Fail during checkout context"~description:"The context checkout failed using a given hash"~pp:(funppf(hash:Context_hash.t)->Format.fprintfppf"@[Failed to checkout the context with hash %a@]"Context_hash.pp_shorthash)Data_encoding.(obj1(req"hash"Context_hash.encoding))(functionFailed_to_checkout_contexth->Someh|_->None)(funh->Failed_to_checkout_contexth);Error_monad.register_error_kind`Temporary~id:"Validator_process.system_error_while_validating"~title:"Failed to validate block because of a system error"~description:"The validator failed because of a system error"~pp:(funppf(errno,fn,msg)->Format.fprintfppf"System error while validating a block (in function %s(%s)):@ %s"fnmsgerrno)Data_encoding.(obj3(req"errno"string)(req"function"string)(req"msg"string))(function|System_error{errno;fn;msg}->Some(errno,fn,msg)|_->None)(fun(errno,fn,msg)->System_error{errno;fn;msg});Error_monad.register_error_kind`Temporary~id:"validator.missing_test_protocol"~title:"Missing test protocol"~description:"Missing test protocol when forking the test chain"~pp:(funppfprotocol->Format.fprintfppf"Missing test protocol %a when forking the test chain."Protocol_hash.ppprotocol)Data_encoding.(obj1(req"test_protocol"Protocol_hash.encoding))(functionMissing_test_protocolprotocol->Someprotocol|_->None)(funprotocol->Missing_test_protocolprotocol);Error_monad.register_error_kind`Temporary~id:"validator.validation_process_failed"~title:"Validation process failed"~description:"Failed to validate block using external validation process."~pp:(funppferror->Format.fprintfppf"Failed to validate block using external validation process. %a"pp_validation_process_errorerror)Data_encoding.(obj1(req"error"validation_process_error_encoding))(functionValidation_process_failederror->Someerror|_->None)(funerror->Validation_process_failederror);Error_monad.register_error_kind`Temporary~id:"validator.cannot_validate_while_shutting_down"~title:"Cannot validate while shutting down"~description:"Cannot validate block while the node is shutting down."~pp:(funppf()->Format.fprintfppf"Cannot validate block while the node is shutting down.")Data_encoding.empty(functionCannot_validate_while_shutting_down->Some()|_->None)(fun()->Cannot_validate_while_shutting_down)letinvalid_blockblockerror=Invalid_block{block;error}