123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 TriliTech <contact@trili.tech> *)(* Copyright (c) 2023 Nomadic Labs, <contact@nomadic-labs.com> *)(* Copyright (c) 2023 Functori, <contact@functori.com> *)(* Copyright (c) 2023 Marigold <contact@marigold.dev> *)(* *)(* 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. *)(* *)(*****************************************************************************)moduleSimple=structincludeInternal_event.Simpleletsection=["smart_rollup_node";"daemon"]lethead_processing=declare_2~section~name:"smart_rollup_node_daemon_process_head"~msg:"Processing head {hash} at level {level}"~level:Notice("hash",Block_hash.encoding)("level",Data_encoding.int32)letnew_head_processed=declare_3~section~name:"smart_rollup_node_daemon_new_head_processed"~msg:"Finished processing layer 1 head {hash} at level {level} in \
{process_time}"~level:Notice("hash",Block_hash.encoding)("level",Data_encoding.int32)("process_time",Time.System.Span.encoding)~pp3:Ptime.Span.ppletnew_head_degraded=declare_2~section~name:"smart_rollup_node_daemon_new_head_degraded"~msg:"[DEGRADED MODE] Seen layer 1 head {hash} at level {level}"~level:Error("hash",Block_hash.encoding)("level",Data_encoding.int32)letprocessing_heads_iteration=declare_3~section~name:"smart_rollup_node_daemon_processing_heads"~msg:"A new iteration of process_heads has been triggered: processing \
{number} heads from level {from} to level {to}"~level:Debug("number",Data_encoding.int31)("from",Data_encoding.int32)("to",Data_encoding.int32)letnew_heads_processed=declare_3~section~name:"smart_rollup_node_daemon_new_heads_processed"~msg:"Finished processing {number} layer 1 heads for levels {from} to {to}"~level:Info("number",Data_encoding.int31)("from",Data_encoding.int32)("to",Data_encoding.int32)letincluded_successful_operation=declare_1~section~name:"smart_rollup_node_daemon_included_successful_operation"~msg:"Operation {operation} was included as successful"~level:Debug("operation",L1_operation.encoding)~pp1:L1_operation.ppletincluded_failed_operation=declare_3~section~name:"smart_rollup_node_daemon_included_failed_operation"~msg:"[Warning]: Operation {operation} was included as {status} with error \
{error}"~level:Warning("operation",L1_operation.encoding)("status",Data_encoding.(string_enum[("failed",`Failed);("backtracked",`Backtracked);("skipped",`Skipped);]))("error",Data_encoding.optionError_monad.trace_encoding)~pp1:L1_operation.pp~pp3:(funppf->function|None->Format.pp_print_stringppf"none"|Somee->Error_monad.pp_print_traceppfe)letmigration=declare_5~name:"smart_rollup_node_daemon_protocol_migration"~msg:"{catching_up} from {old_protocol} ({old_protocol_level}) to \
{new_protocol} ({new_protocol_level}) "~level:Notice("catching_up",Data_encoding.bool)("old_protocol",Protocol_hash.encoding)("old_protocol_level",Data_encoding.int31)("new_protocol",Protocol_hash.encoding)("new_protocol_level",Data_encoding.int31)~pp1:(funppfcatching_up->Format.pp_print_stringppf(ifcatching_upthen"Catching up on migration"else"Migration"))letswitched_protocol=declare_3~name:"smart_rollup_node_daemon_switched_protocol"~msg:"Switched to {protocol} ({proto_level}) with constants {constants} "~level:Notice("protocol",Protocol_hash.encoding)("proto_level",Data_encoding.int31)("constants",Rollup_constants.encoding)~pp3:(funfmtc->Data_encoding.Json.ppfmt(Data_encoding.Json.constructRollup_constants.encodingc))leterror=declare_1~section~name:"smart_rollup_node_daemon_error"~msg:"[Fatal daemon error]: {error}"~level:Fatal("error",trace_encoding)~pp1:pp_print_traceletdegraded_mode=declare_0~section~name:"smart_rollup_node_daemon_degraded_mode"~msg:"[Daemon error]: entering degraded mode - only playing refutation game \
to defend commitments and publishing pending commitments"~level:Error()letrefutation_loop_retry=declare_1~section~name:"smart_rollup_node_daemon_refutation_loop_retry"~msg:"[Refutation daemon error]: restarting refutation daemon in {delay}."~level:Warning("delay",Time.System.Span.encoding)~pp1:Ptime.Span.ppletmain_loop_retry=declare_1~section~name:"smart_rollup_node_daemon_main_loop_retry"~msg:"Restarting main rollup node loop in {delay}."~level:Warning("delay",Time.System.Span.encoding)~pp1:Ptime.Span.ppletexit_bailout_mode=declare_0~section~name:"smart_rollup_node_daemon_exit_bailout_mode"~msg:"Exit bailout mode - stakes have been recovered, and the node is \
exiting safely now"~level:Notice()endlethead_processinghashlevel=Simple.(emithead_processing(hash,level))letnew_head_processedhashlevelprocess_time=Simple.(emitnew_head_processed(hash,level,process_time))letnew_head_degradedhashlevel=Simple.(emitnew_head_degraded(hash,level))letnew_heads_iterationevent=function|oldest::rest->letnewest=matchList.revrestwith[]->oldest|newest::_->newestinletnumber=Int32.subnewest.Layer1.leveloldest.Layer1.level|>Int32.succ|>Int32.to_intinSimple.emitevent(number,oldest.level,newest.level)|[]->Lwt.return_unitletprocessing_heads_iteration=new_heads_iterationSimple.processing_heads_iterationletnew_heads_processed=new_heads_iterationSimple.new_heads_processedletincluded_operation?errorsstatusoperation=matchstatuswith|`Applied->Simple.(emitincluded_successful_operation)operation|`Failed|`Backtracked|`Skipped->Simple.(emitincluded_failed_operation)(operation,status,errors)letmigration~catching_up(old_protocol,old_protocol_level)(new_protocol,new_protocol_level)=Simple.(emitmigration)(catching_up,old_protocol,old_protocol_level,new_protocol,new_protocol_level)letswitched_protocolprotocolproto_levelconstants=Simple.(emitswitched_protocol)(protocol,proto_level,constants)leterrore=Simple.(emiterror)eletdegraded_mode()=Simple.(emitdegraded_mode)()letrefutation_loop_retryd=Simple.(emitrefutation_loop_retry)(Time.System.Span.of_seconds_exnd)letmain_loop_retryd=Simple.(emitmain_loop_retry)(Time.System.Span.of_seconds_exnd)letexit_bailout_mode()=Simple.(emitexit_bailout_mode)()