123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 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. *)(* *)(*****************************************************************************)openProtocol.Alpha_contextopenInjector_sigstypetag=|Commitment|Submit_batch|Finalize_commitment|Remove_commitment|Rejection|Dispatch_withdrawalsmoduleParameters=structtyperollup_node_state=State.tletevents_section=["tx_rollup_node";"injector"]moduleTag=structtypet=tagletcompare=Stdlib.compareletequal=Stdlib.(=)lethash=Hashtbl.hashletstring_of_tag:t->string=function|Submit_batch->"submit_batch"|Commitment->"commitment"|Finalize_commitment->"finalize_commitment"|Remove_commitment->"remove_commitment"|Rejection->"rejection"|Dispatch_withdrawals->"dispatch_withdrawals"letppppft=Format.pp_print_stringppf(string_of_tagt)letencoding:tData_encoding.t=letopenData_encodinginstring_enum(List.map(funt->(string_of_tagt,t))[Submit_batch;Commitment;Finalize_commitment;Remove_commitment;Rejection;Dispatch_withdrawals;])end(* Very coarse approximation for the number of operation we expect for each
block *)lettable_estimated_size=function|Commitment->3|Submit_batch->509|Finalize_commitment->3|Remove_commitment->3|Rejection->3|Dispatch_withdrawals->89lettag_operation(typekind)(op:kindmanager_operation)=matchopwith|Tx_rollup_submit_batch_->SomeSubmit_batch|Tx_rollup_commit_->SomeCommitment|Tx_rollup_finalize_commitment_->SomeFinalize_commitment|Tx_rollup_remove_commitment_->SomeRemove_commitment|Tx_rollup_rejection_->SomeRejection|Tx_rollup_dispatch_tickets_->SomeDispatch_withdrawals|_->Noneletfee_parameter(rollup_node_state:State.t)op=letNode_config.{fee_cap;burn_cap}=Option.fold(tag_operationop)~none:Node_config.default_cost_caps~some:(function|Commitment->rollup_node_state.caps.operator|Submit_batch->rollup_node_state.caps.submit_batch|Finalize_commitment->rollup_node_state.caps.finalize_commitment|Remove_commitment->rollup_node_state.caps.remove_commitment|Rejection->rollup_node_state.caps.rejection|Dispatch_withdrawals->rollup_node_state.caps.dispatch_withdrawals)inInjection.{minimal_fees=Tez.of_mutez_exn100L;minimal_nanotez_per_byte=Q.of_int1000;minimal_nanotez_per_gas_unit=Q.of_int100;force_low_fee=false;fee_cap;burn_cap;}(* Below are dummy values that are only used to approximate the
size. It is thus important that they remain above the real
values if we want the computed size to be an over_approximation
(without having to do a simulation first). *)(* TODO: https://gitlab.com/tezos/tezos/-/issues/2812
check the size, or compute them wrt operation kind *)letapproximate_fee_bound__={fee=Tez.of_mutez_exn3_000_000L;counter=Z.of_int500_000;gas_limit=Gas.Arith.integral_of_int_exn500_000;storage_limit=Z.of_int500_000;}(* TODO: https://gitlab.com/tezos/tezos/-/issues/2813
Decide if some operations must all succeed *)letbatch_must_succeed_=`At_least_oneletignore_failing_operation:typekind.kindmanager_operation->_=function|Tx_rollup_remove_commitment_|Tx_rollup_finalize_commitment_->(* We can keep these operations as there will be at most one of them in
the queue at any given time. *)`Ignore_keep|_->`Don't_ignore(** Returns [true] if an included operation should be re-queued for injection
when the block in which it is included is reverted (due to a
reorganization). *)letrequeue_reverted_operation(typekind)state(operation:kindmanager_operation)=letopenLwt_syntaxinmatchoperationwith|Tx_rollup_rejection_->(* TODO: check if rejected commitment in still in main chain *)return_true|Tx_rollup_commit{commitment;_}->(letlevel=commitment.levelinlet*l2_block=State.get_level_l2_blockstatelevelinmatchl2_blockwith|None->(* We don't know this L2 block, should not happen *)let+()=Debug_events.(emitshould_not_happen)__LOC__infalse|Somel2_block->letcommit_hash=Tx_rollup_commitment.(Compact.hash(Full.compactcommitment))in(* Do not re-queue if commitment for this level has changed *)returnTx_rollup_commitment_hash.(l2_block.L2block.header.commitment=commit_hash))|_->return_trueletoperation_tag(typekind)(operation:kindmanager_operation)=matchoperationwith|Tx_rollup_rejection_->SomeRejection|Tx_rollup_commit_->SomeCommitment|Tx_rollup_submit_batch_->SomeSubmit_batch|Tx_rollup_finalize_commitment_->SomeFinalize_commitment|Tx_rollup_remove_commitment_->SomeRemove_commitment|Tx_rollup_dispatch_tickets_->SomeDispatch_withdrawals|_->NoneendincludeInjector_functor.Make(Parameters)