123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)moduleRequest=structtype('a,'b)t=|Flush:Block_hash.t*Chain_validator_worker_state.update*Block_hash.Set.t*Operation_hash.Set.t->(unit,errortrace)t|Notify:P2p_peer.Id.t*Mempool.t->(unit,Empty.t)t|Leftover:(unit,Empty.t)t|Inject:{op:Operation.t;force:bool}->(unit,errortrace)t|Arrived:Operation_hash.t*Operation.t->(unit,Empty.t)t|Advertise:(unit,Empty.t)t|Ban:Operation_hash.t->(unit,errortrace)ttypeview=View:_t->viewletviewreq=Viewreqletencoding=letopenData_encodinginunion[case(Tag0)~title:"Flush"(obj3(req"request"(constant"flush"))(req"block"Block_hash.encoding)(req"event"Chain_validator_worker_state.update_encoding))(function|View(Flush(hash,event,_,_))->Some((),hash,event)|_->None)(fun((),hash,event)->View(Flush(hash,event,Block_hash.Set.empty,Operation_hash.Set.empty)));case(Tag1)~title:"Notify"(obj3(req"request"(constant"notify"))(req"peer"P2p_peer.Id.encoding)(req"mempool"Mempool.encoding))(function|View(Notify(peer,mempool))->Some((),peer,mempool)|_->None)(fun((),peer,mempool)->View(Notify(peer,mempool)));case(Tag2)~title:"Inject"(obj3(req"request"(constant"inject"))(req"operation"Operation.encoding)(req"force"bool))(function|View(Inject{op;force})->Some((),op,force)|_->None)(fun((),op,force)->View(Inject{op;force}));case(Tag3)~title:"Arrived"(obj3(req"request"(constant"arrived"))(req"operation_hash"Operation_hash.encoding)(req"operation"Operation.encoding))(function|View(Arrived(oph,op))->Some((),oph,op)|_->None)(fun((),oph,op)->View(Arrived(oph,op)));case(Tag4)~title:"Advertise"(obj1(req"request"(constant"advertise")))(functionViewAdvertise->Some()|_->None)(fun()->ViewAdvertise);case(Tag5)~title:"Leftover"(obj1(req"request"(constant"leftover")))(functionViewLeftover->Some()|_->None)(fun()->ViewLeftover);case(Tag6)~title:"Ban"(obj2(req"request"(constant"ban"))(req"operation_hash"Operation_hash.encoding))(functionView(Banoph)->Some((),oph)|_->None)(fun((),oph)->View(Banoph));]letppppf(Viewr)=matchrwith|Flush(hash,_,_,_)->Format.fprintfppf"switching to new head %a"Block_hash.pphash|Notify(id,{Mempool.known_valid;pending})->Format.fprintfppf"@[<v 2>notified by %a of operations"P2p_peer.Id.ppid;Operation_hash.Set.iter(funoph->Format.fprintfppf"@,%a (known_valid)"Operation_hash.ppoph)known_valid;Operation_hash.Set.iter(funoph->Format.fprintfppf"@,%a (pending)"Operation_hash.ppoph)pending;Format.fprintfppf"@]"|Leftover->Format.fprintfppf"process next batch of operation"|Inject{op;force}->Format.fprintfppf"injecting operation %a (force:%b)"Operation_hash.pp(Operation.hashop)force|Arrived(oph,_)->Format.fprintfppf"operation %a arrived"Operation_hash.ppoph|Advertise->Format.fprintfppf"advertising pending operations"|Banoph->Format.fprintfppf"banning operation %a"Operation_hash.ppophendmoduleOperation_encountered=structtypesituation=|Injected|Arrived|NotifiedofP2p_peer_id.toption|Othertypet=situation*Operation_hash.tletencoding=letopenData_encodinginunion~tag_size:`Uint8[case(Tag0)~title:"injected"(obj2(req"situation"(constant"injected"))(req"operation"Operation_hash.encoding))(functionInjected,oph->Some((),oph)|_->None)(fun((),oph)->(Injected,oph));case(Tag1)~title:"arrived"(obj2(req"situation"(constant"arrived"))(req"operation"Operation_hash.encoding))(functionArrived,oph->Some((),oph)|_->None)(fun((),oph)->(Arrived,oph));case(Tag2)~title:"notified"(obj3(req"situation"(constant"notified"))(req"operation"Operation_hash.encoding)(req"peer"(optionP2p_peer_id.encoding)))(functionNotifiedpeer,oph->Some((),oph,peer)|_->None)(fun((),oph,peer)->(Notifiedpeer,oph));case(Tag3)~title:"other"(obj2(req"situation"(constant"other"))(req"operation"Operation_hash.encoding))(functionOther,hash->Some((),hash)|_->None)(fun((),oph)->(Other,oph));]letsituation_ppppf=function|Injected->Format.fprintfppf"injected"|Arrived->Format.fprintfppf"arrived"|NotifiedNone->Format.fprintfppf"notified from the previous run"|Notified(Somepid)->Format.fprintfppf"notified from %a"P2p_peer_id.pppid|Other->Format.fprintfppf"encountered"letppppf(situation,oph)=Format.fprintfppf"operation %a: %a"situation_ppsituationOperation_hash.ppophend