123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159(*****************************************************************************)(* *)(* 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:Configuration.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)letsafety_guard=function|Operation.Publish_->(* Gas consumption of commitment publication can increase if there are
already commitments for the same level in the context. The value 300
was inferred empirically by looking at gas consumption on a running
rollup, and is sufficient to cover the difference in the case where a
commitment for the same level already exists. *)Some300|Timeout_|Refute_->(* We increase safety of refutation game operations by precaution. *)Some300|Add_messages_|Cement_|Recover_bond_|Execute_outbox_message_->Noneletpersist_operation(op:Operation.t)=matchopwith|Cement_|Publish_(* Cement and Publish commitments don't need to be persisted as they are
requeued by the node automatically. *)|Refute_|Timeout_(* Refutation game operations don't need to be persisted as they are
requeued by the node automatically depending on the state of the game on
L1 on startup. *)->false|Add_messages_|Recover_bond_|Execute_outbox_message_->trueletretry_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:
- 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. *)matchopwith|Cement_|Publish_->(* Cement and Publish commitments can be forgotten to free up the
injector as they are requeued by the node automatically. *)returnForget|Refute_|Timeout_|Add_messages_|Recover_bond_|Execute_outbox_message_->(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