123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 Functori, <contact@functori.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. *)(* *)(*****************************************************************************)openInjector_sigstypestate={cctxt:Client_context.full;fee_parameters:Operation_kind.fee_parameters;minimal_block_delay:int64;delay_increment_per_round:int64;}moduleParameters:PARAMETERSwithtypestate=stateandtypeTag.t=Operation_kind.tandtypeOperation.t=L1_operation.t=structtypenonrecstate=stateletevents_section=["smart_rollup_node"]moduleTag:TAGwithtypet=Operation_kind.t=structtypet=Operation_kind.tletcompare=Stdlib.compareletequal=Stdlib.(=)lethash=Hashtbl.hashletstring_of_tag=Operation_kind.to_stringletppppft=Format.pp_print_stringppf(string_of_tagt)letencoding:tData_encoding.t=Operation_kind.encodingendmoduleOperation=L1_operation(* TODO: https://gitlab.com/tezos/tezos/-/issues/3459
Very coarse approximation for the number of operation we
expect for each block *)lettable_estimated_size:Tag.t->int=function|Publish->1|Add_messages->100|Cement->1|Timeout->1|Refute->1|Recover->1|Execute_outbox_message->1letoperation_tag:Operation.t->Tag.t=function|Add_messages_->Add_messages|Cement_->Cement|Publish_->Publish|Timeout_->Timeout|Refute_->Refute|Recover_bond_->Recover|Execute_outbox_message_->Execute_outbox_messageletfee_parameter{fee_parameters;_}operation=letoperation_kind=operation_tagoperationinOperation_kind.Map.findoperation_kindfee_parameters|>Option.value~default:(Configuration.default_fee_parameteroperation_kind)(* TODO: https://gitlab.com/tezos/tezos/-/issues/3459
Decide if some batches must have all the operations succeed. See
{!Injector_sigs.Parameter.batch_must_succeed}. *)letbatch_must_succeed_=`At_least_oneletretry_unsuccessful_operation_state(_op:Operation.t)status=letopenLwt_syntaxinmatchstatuswith|Backtracked|Skipped|Other_branch->(* Always retry backtracked or skipped operations, or operations that
are on another branch because of a reorg:
- Commitments are always produced on finalized blocks. They don't
need to be recomputed, and as such are valid in another branch.
- The cementation operations should be re-injected because the node
only keeps track of the last cemented level and the last published
commitment, without rollbacks.
- Messages posted to an inbox should be re-emitted (i.e. re-queued)
in case of a fork.
- Timeout should be re-submitted as the timeout may be reached as well
on the other branch.
- Refutation should be re-submitted in case of fork.
TODO: https://gitlab.com/tezos/tezos/-/issues/3459
maybe check if game exists on other branch as well.
*)returnRetry|Failederror->((* TODO: https://gitlab.com/tezos/tezos/-/issues/4071
Think about which operations should be retried and when. *)matchclassify_traceerrorwith|Permanent|Outdated->returnForget|Branch|Temporary->returnRetry)|Never_included->(* Forget operations that are never included *)returnForgetendincludeInjector_functor.Make(Parameters)letcheck_and_add_pending_operation(mode:Configuration.mode)(operation:L1_operation.t)=letopenLwt_result_syntaxinifConfiguration.(can_injectmode(Parameters.operation_tagoperation))thenlet*hash=add_pending_operationoperationinreturn(Somehash)elsereturnNone