{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
module Test.Consensus.Leios.LeiosFetch.Node (tests) where
import Cardano.Crypto.Hash (Hash (UnsafeHash), hashToBytes)
import Cardano.Ledger.Dijkstra (DijkstraEra)
import Cardano.Network.NodeToNode (chainSyncMiniProtocolNum, defaultMiniProtocolParameters)
import Cardano.Network.NodeToNode.Version (NodeToNodeVersion (..))
import qualified Codec.CBOR.Encoding as CBOR
import qualified Codec.CBOR.Write as CBOR
import Control.Concurrent.Class.MonadSTM.Strict
import Control.Monad (forM, forM_, replicateM, replicateM_, unless, void)
import Control.Monad.Class.MonadAsync (withAsync)
import Control.Monad.Class.MonadThrow
import Control.Monad.Class.MonadTime.SI (DiffTime, Time (..), addTime, diffTime, getMonotonicTime)
import Control.Monad.Class.MonadTimer.SI (threadDelay, timeout)
import Control.Monad.Except (runExcept, runExceptT)
import Control.Monad.IOSim (IOSim, runSimOrThrow)
import Control.Tracer (nullTracer)
import Data.Bifunctor (first)
import Data.Bits ((.|.))
import qualified Data.Bits as Bits
import qualified Data.ByteString as BS
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Short as SBS
import Data.Functor ((<&>))
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Maybe (listToMaybe, mapMaybe)
import Data.Maybe.Strict (StrictMaybe (SNothing))
import Data.Proxy (Proxy (..))
import Data.Time (NominalDiffTime, addUTCTime)
import qualified Data.Vector.Strict as V
import Data.Word (Word32)
import Network.TypedProtocol.Codec (PeerRole (..))
import Network.TypedProtocol.Core (IsPipelined (..), ReflRelativeAgency (..))
import Network.TypedProtocol.Peer (Peer (..))
import Ouroboros.Consensus.Block
( Header
, Point
, SlotNo (..)
, WithOrigin (..)
, blockHash
, blockPoint
, blockSlot
, pointSlot
, withOrigin
, pattern GenesisPoint
)
import Ouroboros.Consensus.BlockchainTime.WallClock.Default (defaultSystemTime)
import Ouroboros.Consensus.BlockchainTime.WallClock.Types (SystemStart (SystemStart))
import Ouroboros.Consensus.Config (configBlock, configLedger)
import Ouroboros.Consensus.Config.SupportsNode (getSystemStart)
import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (..))
import Ouroboros.Consensus.Ledger.Tables.Utils (forgetLedgerTables)
import Ouroboros.Consensus.Leios.Acquisitions
( LeiosAcquisition (..)
, LeiosAcquisitions (..)
)
import Ouroboros.Consensus.Leios.AnnounceState (newAnnounceState)
import qualified Ouroboros.Consensus.Leios.NotifyLog as NotifyLog
import Ouroboros.Consensus.Leios.Types
( BytesSize
, EndorserBlock
, EndorserBlockHash
, LeiosPoint (..)
, LeiosTx (..)
, LeiosVote
, Serialised (..)
, TxHash
, deserialiseEndorserBlock
, encodeEndorserBlockSize
, endorserBlockHash
, endorserBlockReferences
, hashLeiosTx
, mkEndorserBlock
, serialiseEndorserBlock
, toRankingBlockHash
)
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck as InFutureCheck
import Ouroboros.Consensus.MiniProtocol.LeiosFetch.Client.Replies
( ExnLeiosFetchInvalidReply (..)
, LeiosFetchClientContext (..)
)
import Ouroboros.Consensus.MiniProtocol.LeiosFetch.Decision
( LeiosOutstanding (..)
, OfferedHalves (..)
, PeerOffer (..)
, isFocusedPoint
)
import Ouroboros.Consensus.MiniProtocol.LeiosFetch.Kernel
( ExnLeiosTwoCertificationClaims (..)
, LeiosFetchKernel (..)
, LeiosFetchPeer (..)
, LeiosPeerLifetimeId (..)
, recordLeiosOffer
, withLeiosFetchPeer
)
import Ouroboros.Consensus.MiniProtocol.LeiosFetch.Server
( ExnLeiosInvalidRequest (..)
, LeiosFetchRequestHandler (..)
, leiosFetchServerPeer
)
import Ouroboros.Consensus.MiniProtocol.LeiosFetch.Type
import Ouroboros.Consensus.MiniProtocol.LeiosNotify.Client
( leiosNotifyClientPeerPipelined
, toLeiosNotifyClientPeerPipelined
)
import Ouroboros.Consensus.MiniProtocol.LeiosNotify.Client.Announcements.Validation
( defaultLeiosAnnouncementAgeLimits
, maxAnnouncementAgeRecv
, maxAnnouncementAgeSend
)
import Ouroboros.Consensus.MiniProtocol.LeiosNotify.Client.State
( ExnLeiosNotifyInvalidOffer (..)
, checkLeiosBlockOffer
, checkLeiosClosureOffer
, emptyLeiosNotifyPeerState
, onLeiosNotifyAnnouncement
, pruneLeiosNotifyPeerState
)
import Ouroboros.Consensus.MiniProtocol.LeiosNotify.Server
( WhetherExcessiveRequests (..)
, leiosNotifyServerPeerLookahead
)
import Ouroboros.Consensus.MiniProtocol.LeiosNotify.Type
( LeiosNotify
, Message
( MsgCanceled
, MsgLeiosBlockAnnouncement
, MsgLeiosBlockOffer
, MsgLeiosBlockTxsOffer
, MsgLeiosVotes
)
, byteLimitsLeiosNotify
, timeLimitsLeiosNotify
)
import qualified Ouroboros.Consensus.MiniProtocol.LeiosNotify.Type as LN
import Ouroboros.Consensus.Network.LeiosFetch (leiosFetchMiniProtocolNum)
import Ouroboros.Consensus.Network.LeiosNotify
( leiosNotifyMiniProtocolNum
, runLookaheadFixedSenderPeerWithLimits
)
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
import Ouroboros.Consensus.NodeKernel (NodeKernel (..), leiosDeadlinePrunerInterval)
import qualified Ouroboros.Consensus.Storage.ChainDB.API as ChainDB
import Ouroboros.Consensus.Storage.LeiosDB (newLeiosDBInMemory)
import Ouroboros.Consensus.Storage.LeiosDB.API
( LeiosDbWriter (..)
, Promise (..)
, withWriter
)
import qualified Ouroboros.Consensus.Util.IOLike as IOLike
import Ouroboros.Network.Block (Tip (..))
import Ouroboros.Network.Channel (Channel)
import Ouroboros.Network.ConnectionId (ConnectionId (..))
import Ouroboros.Network.Driver.Limits (runPipelinedPeerWithLimits)
import Ouroboros.Network.Driver.Simple (runPeer)
import Ouroboros.Network.Mux
( MiniProtocol (..)
, TemperatureBundle (..)
, WithProtocolTemperature (..)
)
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (IsBigLedgerPeer (..))
import Test.Consensus.Leios.Committee (certOf)
import Test.Consensus.Leios.Environment
import Test.Consensus.Leios.NodeUnderTest
import Test.Consensus.Leios.TestBlock
( LedgerState (..)
, LeiosTestBlock (..)
, firstLeiosBlock
, forkLeiosBlock
, leiosTestInitExtLedger
, setAnnouncement
, setLeiosCert
, successorLeiosBlock
)
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck
( Gen
, Property
, checkCoverage
, choose
, cover
, elements
, forAll
, ioProperty
, oneof
, sublistOf
, suchThat
, tabulate
, testProperty
, withNumTests
, (===)
)
import Test.Util.ChainDB (emptyNodeDBs)
tests :: TestTree
tests :: TestTree
tests =
[Char] -> [TestTree] -> TestTree
testGroup
[Char]
"node vs environment"
[ [Char] -> Property -> TestTree
forall a. Testable a => [Char] -> a -> TestTree
testProperty
[Char]
"the node's server serves what it holds, disconnects a client that requests anything else, and ends when the client sends MsgDone"
Property
prop_serverAnswers
, [Char] -> Assertion -> TestTree
testCase [Char]
"the node serves an endorser block in the bytes it received" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ do
HasCallStack => [Char] -> Bool -> Assertion
[Char] -> Bool -> Assertion
assertBool [Char]
"the bytes are canonical" (Bool -> Assertion) -> Bool -> Assertion
forall a b. (a -> b) -> a -> b
$
Serialised EndorserBlock
nonCanonicalBytes Serialised EndorserBlock -> Serialised EndorserBlock -> Bool
forall a. Eq a => a -> a -> Bool
/= EndorserBlock -> Serialised EndorserBlock
serialiseEndorserBlock ([(TxHash, Word32)] -> EndorserBlock
mkEndorserBlock [(TxHash, Word32)]
nonCanonicalReferences)
(forall s. IOSim s ([Reply], ServerOutcome))
-> IO ([Reply], ServerOutcome)
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing ([Request] -> IOSim s ([Reply], ServerOutcome)
forall s. [Request] -> IOSim s ([Reply], ServerOutcome)
nodeAnswers [LeiosPoint -> Request
RequestBlock LeiosPoint
nonCanonicalPoint])
IO ([Reply], ServerOutcome)
-> (([Reply], ServerOutcome) -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (([Reply], ServerOutcome) -> ([Reply], ServerOutcome) -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= ([Serialised EndorserBlock -> Reply
ReplyBlock Serialised EndorserBlock
nonCanonicalBytes], ServerOutcome
ServerEnded))
, [Char] -> Assertion -> TestTree
testCase [Char]
"the node fetches the endorser block a header its peer rolls forward certifies" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$
(forall s. IOSim s [Acquired]) -> IO [Acquired]
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s [Acquired]
forall s. IOSim s [Acquired]
nodeFetchesCertified
IO [Acquired] -> ([Acquired] -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Acquired] -> [Acquired] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [LeiosPoint -> Acquired
AcquiredBody LeiosPoint
fetchedPoint, LeiosPoint -> Acquired
AcquiredClosure LeiosPoint
fetchedPoint])
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node fetches an endorser block that headers its peer rolls forward announce and certify, and offers it on"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s ([Acquired], [Relayed]))
-> IO ([Acquired], [Relayed])
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s ([Acquired], [Relayed])
forall s. IOSim s ([Acquired], [Relayed])
nodeFetchesRolledForward
IO ([Acquired], [Relayed])
-> (([Acquired], [Relayed]) -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ( ([Acquired], [Relayed]) -> ([Acquired], [Relayed]) -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?=
( [LeiosPoint -> Acquired
AcquiredBody LeiosPoint
fetchedPoint, LeiosPoint -> Acquired
AcquiredClosure LeiosPoint
fetchedPoint]
, LeiosPoint -> [Relayed]
relayedFetchedAt LeiosPoint
fetchedPoint
)
)
, [Char] -> Assertion -> TestTree
testCase [Char]
"the node takes a peer that jumps over a certifying header as offering what it certifies" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$
(forall s. IOSim s [Bool]) -> IO [Bool]
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s [Bool]
forall s. IOSim s [Bool]
nodeRecordsJumperOffers IO [Bool] -> ([Bool] -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Bool] -> [Bool] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [Bool
True, Bool
True])
, [Char] -> Assertion -> TestTree
testCase [Char]
"the node fetches what a certifying header certifies from a peer that jumps over it" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$
(forall s. IOSim s (Point LeiosTestBlock))
-> IO (Point LeiosTestBlock)
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s (Point LeiosTestBlock)
forall s. IOSim s (Point LeiosTestBlock)
nodeFetchesFromJumper IO (Point LeiosTestBlock)
-> (Point LeiosTestBlock -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Point LeiosTestBlock -> Point LeiosTestBlock -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [LeiosTestBlock] -> Point LeiosTestBlock
lastPoint [LeiosTestBlock]
jumpedChain)
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node fetches what a certifying header certifies from a jumper whose jump over it starts at the announcing header"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> IO ([WithOrigin SlotNo], Point LeiosTestBlock)
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
forall s. IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
nodeFetchesFromJumperInSteps
IO ([WithOrigin SlotNo], Point LeiosTestBlock)
-> (([WithOrigin SlotNo], Point LeiosTestBlock) -> Assertion)
-> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ( ([WithOrigin SlotNo], Point LeiosTestBlock)
-> ([WithOrigin SlotNo], Point LeiosTestBlock) -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?=
( [SlotNo -> WithOrigin SlotNo
forall t. t -> WithOrigin t
NotOrigin (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingFetched), SlotNo -> WithOrigin SlotNo
forall t. t -> WithOrigin t
NotOrigin (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
certifyingFetched)]
, [LeiosTestBlock] -> Point LeiosTestBlock
lastPoint [LeiosTestBlock]
jumpedChain
)
)
, [Char] -> Assertion -> TestTree
testCase [Char]
"the node records no offer older than the slot it pruned its peers' offers to" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$
(forall s. IOSim s [SlotNo]) -> IO [SlotNo]
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s [SlotNo]
forall s. IOSim s [SlotNo]
nodeIgnoresPrunedOffer IO [SlotNo] -> ([SlotNo] -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([SlotNo] -> [SlotNo] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [Word64 -> SlotNo
SlotNo Word64
5])
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node disconnects a peer that rolls forward certificates of two endorser blocks for one election"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s.
IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> IO
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
forall s.
IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
nodeDisconnectsDoubleCertifier
IO
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
-> (Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
-> Assertion)
-> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
-> Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
-> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= (Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
-> Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
forall a. a -> Maybe a
Just (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb, Hash HASH EraIndependentEbReferences
otherEbHash))
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node fetches and selects what a certificate certifies at an election's third announcement, which it does not relay"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s (Point LeiosTestBlock, [Relayed]))
-> IO (Point LeiosTestBlock, [Relayed])
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s (Point LeiosTestBlock, [Relayed])
forall s. IOSim s (Point LeiosTestBlock, [Relayed])
nodeFetchesCertifiedThird
IO (Point LeiosTestBlock, [Relayed])
-> ((Point LeiosTestBlock, [Relayed]) -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ((Point LeiosTestBlock, [Relayed])
-> (Point LeiosTestBlock, [Relayed]) -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= (LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint LeiosTestBlock
certifyingFetched, [Relayed
RelayedAnnouncement, Relayed
RelayedAnnouncement]))
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node fetches an endorser block a later election announced, once it prunes the earlier announcement"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s ([Acquired], [Relayed]))
-> IO ([Acquired], [Relayed])
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s ([Acquired], [Relayed])
forall s. IOSim s ([Acquired], [Relayed])
nodeFetchesAfterPruningEarlier
IO ([Acquired], [Relayed])
-> (([Acquired], [Relayed]) -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ( ([Acquired], [Relayed]) -> ([Acquired], [Relayed]) -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?=
( [LeiosPoint -> Acquired
AcquiredBody LeiosPoint
refocusedPoint, LeiosPoint -> Acquired
AcquiredClosure LeiosPoint
refocusedPoint]
, Relayed
RelayedAnnouncement Relayed -> [Relayed] -> [Relayed]
forall a. a -> [a] -> [a]
: LeiosPoint -> [Relayed]
relayedFetchedAt LeiosPoint
refocusedPoint
)
)
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node selects a block certifying an endorser block though a rival announcement took the focus first, whichever of the announcing and certifying blocks arrives first"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ [CertifyingArrival]
-> (CertifyingArrival -> Assertion) -> Assertion
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [CertifyingArrival
forall a. Bounded a => a
minBound .. CertifyingArrival
forall a. Bounded a => a
maxBound]
((CertifyingArrival -> Assertion) -> Assertion)
-> (CertifyingArrival -> Assertion) -> Assertion
forall a b. (a -> b) -> a -> b
$ \CertifyingArrival
arrival ->
(forall s. IOSim s (Bool, Point LeiosTestBlock, [Relayed]))
-> IO (Bool, Point LeiosTestBlock, [Relayed])
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing (CertifyingArrival
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed])
forall s.
CertifyingArrival
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed])
nodeSelectsCertifiedRival CertifyingArrival
arrival)
IO (Bool, Point LeiosTestBlock, [Relayed])
-> ((Bool, Point LeiosTestBlock, [Relayed]) -> Assertion)
-> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char]
-> (Bool, Point LeiosTestBlock, [Relayed])
-> (Bool, Point LeiosTestBlock, [Relayed])
-> Assertion
forall a.
(Eq a, Show a, HasCallStack) =>
[Char] -> a -> a -> Assertion
assertEqual
(CertifyingArrival -> [Char]
forall a. Show a => a -> [Char]
show CertifyingArrival
arrival)
(Bool
True, LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint LeiosTestBlock
certifyingFetched, [Relayed]
relayedFetchedAfterRival)
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node fetches an endorser block at the size its peer offers, though the announcement states another"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s [Acquired]) -> IO [Acquired]
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s [Acquired]
forall s. IOSim s [Acquired]
nodeFetchesAtOfferedSize
IO [Acquired] -> ([Acquired] -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Acquired] -> [Acquired] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [LeiosPoint -> Acquired
AcquiredBody LeiosPoint
fetchedPoint, LeiosPoint -> Acquired
AcquiredClosure LeiosPoint
fetchedPoint])
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node selects a block certifying an endorser block that another election announced at another size"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s (Point LeiosTestBlock))
-> IO (Point LeiosTestBlock)
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s (Point LeiosTestBlock)
forall s. IOSim s (Point LeiosTestBlock)
nodeSelectsDespiteMisstatedSize
IO (Point LeiosTestBlock)
-> (Point LeiosTestBlock -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Point LeiosTestBlock -> Point LeiosTestBlock -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint LeiosTestBlock
certifyingFetched)
, [Char] -> Property -> TestTree
forall a. Testable a => [Char] -> a -> TestTree
testProperty
[Char]
"the node acquires an endorser block whose body and closure the ledger admits, and otherwise acquires nothing of it and disconnects the peer that served it"
Property
prop_boundedEb
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node selects a block certifying an endorser block once the block arrives again after a restart forgot it"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s.
IOSim
s ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed])))
-> IO ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
forall s.
IOSim s ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
nodeReselectsForgotten
IO ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> (((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> Assertion)
-> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= ((Int
1, Bool
True), (Bool
True, Int
0, [LeiosTestBlock] -> Point LeiosTestBlock
lastPoint [LeiosTestBlock]
forgottenChain, [Relayed]
relayedFetchedAfterRival)))
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node relays an announcement to a peer that connects after it, before offering that peer the endorser block"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s [Relayed]) -> IO [Relayed]
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s [Relayed]
forall s. IOSim s [Relayed]
nodeAnnouncesToLateListener
IO [Relayed] -> ([Relayed] -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ( [Relayed] -> [Relayed] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?=
LeiosPoint -> [Relayed]
relayedFetchedAt LeiosPoint
fetchedPoint
)
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node disconnects a peer that offers an endorser block's body again once the node has requested it"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ (forall s. IOSim s (Maybe [Char])) -> IO (Maybe [Char])
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing IOSim s (Maybe [Char])
forall s. IOSim s (Maybe [Char])
nodeDisconnectsReofferAfterRequest
IO (Maybe [Char]) -> (Maybe [Char] -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe [Char] -> Maybe [Char] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just (ExnLeiosNotifyInvalidOffer -> [Char]
forall a. Show a => a -> [Char]
show (LeiosPoint -> ExnLeiosNotifyInvalidOffer
ExnLeiosRepeatedBlockOffer LeiosPoint
fetchedPoint)))
, [Char] -> Assertion -> TestTree
testCase
[Char]
"the node does not offer the closure of an endorser block that misstates the size of a transaction, whether the node holds that transaction already or fetches it afterwards"
(Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ [LieArrival] -> (LieArrival -> Assertion) -> Assertion
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [LieArrival
forall a. Bounded a => a
minBound .. LieArrival
forall a. Bounded a => a
maxBound]
((LieArrival -> Assertion) -> Assertion)
-> (LieArrival -> Assertion) -> Assertion
forall a b. (a -> b) -> a -> b
$ \LieArrival
arrival ->
(forall s. IOSim s [Relayed]) -> IO [Relayed]
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing (LieArrival -> IOSim s [Relayed]
forall s. LieArrival -> IOSim s [Relayed]
nodeOffersLyingEb LieArrival
arrival)
IO [Relayed] -> ([Relayed] -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> [Relayed] -> [Relayed] -> Assertion
forall a.
(Eq a, Show a, HasCallStack) =>
[Char] -> a -> a -> Assertion
assertEqual
(LieArrival -> [Char]
forall a. Show a => a -> [Char]
show LieArrival
arrival)
( case LieArrival
arrival of
LieArrival
TxBeforeBody -> [Relayed]
relayedHonestEb [Relayed] -> [Relayed] -> [Relayed]
forall a. Semigroup a => a -> a -> a
<> [Relayed]
relayedLyingEb
LieArrival
BodyBeforeTx -> [Relayed]
relayedLyingEb [Relayed] -> [Relayed] -> [Relayed]
forall a. Semigroup a => a -> a -> a
<> [Relayed]
relayedHonestEb
)
, [Char] -> Property -> TestTree
forall a. Testable a => [Char] -> a -> TestTree
testProperty
[Char]
"the node relays an announcement, and offers at its point, to a listener that connects before the node stops relaying it, and nothing to one that connects after, whatever the listener's immutable tip and clock"
Property
prop_listenerReach
, [Char] -> Assertion -> TestTree
testCase [Char]
"the node runs LeiosFetch from NodeToNodeV_16 on, and not before" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$
[NodeToNodeVersion]
-> (NodeToNodeVersion -> Assertion) -> Assertion
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [NodeToNodeVersion
forall a. Bounded a => a
minBound .. NodeToNodeVersion
forall a. Bounded a => a
maxBound] ((NodeToNodeVersion -> Assertion) -> Assertion)
-> (NodeToNodeVersion -> Assertion) -> Assertion
forall a b. (a -> b) -> a -> b
$ \NodeToNodeVersion
ntnVersion -> do
let runs :: Bool
runs = NodeToNodeVersion
ntnVersion NodeToNodeVersion -> NodeToNodeVersion -> Bool
forall a. Ord a => a -> a -> Bool
>= NodeToNodeVersion
NodeToNodeV_16
(forall s. IOSim s (Bool, Bool)) -> IO (Bool, Bool)
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing (NodeToNodeVersion -> IOSim s (Bool, Bool)
forall s. NodeToNodeVersion -> IOSim s (Bool, Bool)
nodeRunsLeiosFetch NodeToNodeVersion
ntnVersion) IO (Bool, Bool) -> ((Bool, Bool) -> Assertion) -> Assertion
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> (Bool, Bool) -> (Bool, Bool) -> Assertion
forall a.
(Eq a, Show a, HasCallStack) =>
[Char] -> a -> a -> Assertion
assertEqual (NodeToNodeVersion -> [Char]
forall a. Show a => a -> [Char]
show NodeToNodeVersion
ntnVersion) (Bool
runs, Bool
runs)
]
runSimFinishing :: (forall s. IOSim s a) -> IO a
runSimFinishing :: forall a. (forall s. IOSim s a) -> IO a
runSimFinishing = DiffTime -> (forall s. IOSim s a) -> IO a
forall a. DiffTime -> (forall s. IOSim s a) -> IO a
runSimFinishingWithin DiffTime
100
runSimFinishingWithin :: DiffTime -> (forall s. IOSim s a) -> IO a
runSimFinishingWithin :: forall a. DiffTime -> (forall s. IOSim s a) -> IO a
runSimFinishingWithin DiffTime
limit forall s. IOSim s a
sim = case (forall s. IOSim s (Maybe a)) -> Maybe a
forall a. (forall s. IOSim s a) -> a
runSimOrThrow (DiffTime -> IOSim s a -> IOSim s (Maybe a)
forall a. DiffTime -> IOSim s a -> IOSim s (Maybe a)
forall (m :: * -> *) a.
MonadTimer m =>
DiffTime -> m a -> m (Maybe a)
timeout DiffTime
limit IOSim s a
forall s. IOSim s a
sim) of
Maybe a
Nothing -> [Char] -> IO a
forall a. HasCallStack => [Char] -> IO a
assertFailure ([Char] -> IO a) -> [Char] -> IO a
forall a b. (a -> b) -> a -> b
$ [Char]
"the simulation did not finish within " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> DiffTime -> [Char]
forall a. Show a => a -> [Char]
show DiffTime
limit
Just a
a -> a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
data Acquired = AcquiredBody LeiosPoint | AcquiredClosure LeiosPoint
deriving (Acquired -> Acquired -> Bool
(Acquired -> Acquired -> Bool)
-> (Acquired -> Acquired -> Bool) -> Eq Acquired
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Acquired -> Acquired -> Bool
== :: Acquired -> Acquired -> Bool
$c/= :: Acquired -> Acquired -> Bool
/= :: Acquired -> Acquired -> Bool
Eq, Int -> Acquired -> [Char] -> [Char]
[Acquired] -> [Char] -> [Char]
Acquired -> [Char]
(Int -> Acquired -> [Char] -> [Char])
-> (Acquired -> [Char])
-> ([Acquired] -> [Char] -> [Char])
-> Show Acquired
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> Acquired -> [Char] -> [Char]
showsPrec :: Int -> Acquired -> [Char] -> [Char]
$cshow :: Acquired -> [Char]
show :: Acquired -> [Char]
$cshowList :: [Acquired] -> [Char] -> [Char]
showList :: [Acquired] -> [Char] -> [Char]
Show)
data Relayed
= RelayedAnnouncement
| RelayedBlockOffer LeiosPoint BytesSize
| RelayedBlockTxsOffer LeiosPoint
| RelayedVotes
|
RelayedDishonestly String
deriving (Relayed -> Relayed -> Bool
(Relayed -> Relayed -> Bool)
-> (Relayed -> Relayed -> Bool) -> Eq Relayed
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Relayed -> Relayed -> Bool
== :: Relayed -> Relayed -> Bool
$c/= :: Relayed -> Relayed -> Bool
/= :: Relayed -> Relayed -> Bool
Eq, Int -> Relayed -> [Char] -> [Char]
[Relayed] -> [Char] -> [Char]
Relayed -> [Char]
(Int -> Relayed -> [Char] -> [Char])
-> (Relayed -> [Char])
-> ([Relayed] -> [Char] -> [Char])
-> Show Relayed
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> Relayed -> [Char] -> [Char]
showsPrec :: Int -> Relayed -> [Char] -> [Char]
$cshow :: Relayed -> [Char]
show :: Relayed -> [Char]
$cshowList :: [Relayed] -> [Char] -> [Char]
showList :: [Relayed] -> [Char] -> [Char]
Show)
fetchedTxs :: V.Vector LeiosTx
fetchedTxs :: Vector LeiosTx
fetchedTxs = [LeiosTx] -> Vector LeiosTx
forall a. [a] -> Vector a
V.fromList [ByteString -> LeiosTx
MkLeiosTx (Int -> Word8 -> ByteString
BS.replicate Int
100 Word8
i) | Word8
i <- [Word8
1, Word8
2, Word8
3]]
fetchedEb :: EndorserBlock
fetchedEb :: EndorserBlock
fetchedEb =
[(TxHash, Word32)] -> EndorserBlock
mkEndorserBlock
[(LeiosTx -> TxHash
hashLeiosTx LeiosTx
tx, Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length (LeiosTx -> ByteString
leiosTxBytes LeiosTx
tx))) | LeiosTx
tx <- Vector LeiosTx -> [LeiosTx]
forall a. Vector a -> [a]
V.toList Vector LeiosTx
fetchedTxs]
announcingFetched :: LeiosTestBlock
announcingFetched :: LeiosTestBlock
announcingFetched =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement
(EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb)
(EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb)
(Word64 -> LeiosTestBlock
firstLeiosBlock Word64
0)
fetchedPoint :: LeiosPoint
fetchedPoint :: LeiosPoint
fetchedPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingFetched) (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb)
reannouncingFetched :: LeiosTestBlock
reannouncingFetched :: LeiosTestBlock
reannouncingFetched =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement
(EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb)
(EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb)
(LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock LeiosTestBlock
announcingFetched)
refocusedPoint :: LeiosPoint
refocusedPoint :: LeiosPoint
refocusedPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
reannouncingFetched) (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb)
certifyingFetched :: LeiosTestBlock
certifyingFetched :: LeiosTestBlock
certifyingFetched = LeiosTestBlock -> LeiosTestBlock
certifying LeiosTestBlock
announcingFetched
certifying :: LeiosTestBlock -> LeiosTestBlock
certifying :: LeiosTestBlock -> LeiosTestBlock
certifying LeiosTestBlock
announcing =
LeiosCert -> LeiosTestBlock -> LeiosTestBlock
setLeiosCert
(RankingBlockHash -> [Word16] -> LeiosCert
certOf (Proxy LeiosTestBlock
-> HeaderHash LeiosTestBlock -> RankingBlockHash
forall blk.
ConvertRawHash blk =>
Proxy blk -> HeaderHash blk -> RankingBlockHash
toRankingBlockHash (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @LeiosTestBlock) (LeiosTestBlock -> HeaderHash LeiosTestBlock
forall b. HasHeader b => b -> HeaderHash b
blockHash LeiosTestBlock
announcing)) [Word16
0, Word16
1, Word16
2])
(LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock LeiosTestBlock
announcing)
otherEbHash :: EndorserBlockHash
otherEbHash :: Hash HASH EraIndependentEbReferences
otherEbHash = ShortByteString -> Hash HASH EraIndependentEbReferences
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
UnsafeHash (Int -> Word8 -> ShortByteString
SBS.replicate Int
32 Word8
3)
announcingOther :: LeiosTestBlock
announcingOther :: LeiosTestBlock
announcingOther =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement Hash HASH EraIndependentEbReferences
otherEbHash (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb) (LeiosTestBlock -> LeiosTestBlock
forkLeiosBlock LeiosTestBlock
announcingFetched)
announcingAnother :: LeiosTestBlock
announcingAnother :: LeiosTestBlock
announcingAnother =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement Hash HASH EraIndependentEbReferences
anotherEbHash (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb) (LeiosTestBlock -> LeiosTestBlock
forkLeiosBlock LeiosTestBlock
announcingOther)
anotherEbHash :: EndorserBlockHash
anotherEbHash :: Hash HASH EraIndependentEbReferences
anotherEbHash = ShortByteString -> Hash HASH EraIndependentEbReferences
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
UnsafeHash (Int -> Word8 -> ShortByteString
SBS.replicate Int
32 Word8
4)
nodeFetchesCertifiedThird :: IOSim s (Point LeiosTestBlock, [Relayed])
nodeFetchesCertifiedThird :: forall s. IOSim s (Point LeiosTestBlock, [Relayed])
nodeFetchesCertifiedThird = (NodeUnderTest (IOSim s)
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock, [Relayed])
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s)
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> (NodeUnderTest (IOSim s)
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock, [Relayed])
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
heard <- NodeUnderTest (IOSim s) -> IOSim s (Listener s)
forall s. NodeUnderTest (IOSim s) -> IOSim s (Listener s)
newListener NodeUnderTest (IOSim s)
node
announcerNotifications <- newTQueueIO
holderNotifications <- newTQueueIO
atomically $ do
mapM_
(writeTQueue announcerNotifications . MsgLeiosBlockAnnouncement . ltbHeader)
[announcingOther, announcingAnother]
mapM_ (writeTQueue holderNotifications) (announcingAndOffering fetchedEb announcingFetched)
let announcer =
(NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
listening NodeUnderTest (IOSim s)
node Listener s
heard){epLeiosNotifyServer = feedingLeiosNotifyServer node announcerNotifications}
holder =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
holderNotifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
threadDelay 20
withNodeVsEnvConnection node (PeerAddr 1) announcer $ \NodeVsEnvConnection (IOSim s)
_announcerConn -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) [Relayed] -> STM (IOSim s) [Relayed]
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar (Listener s -> StrictTVar (IOSim s) [Relayed]
forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed Listener s
heard) STM (IOSim s) [Relayed]
-> ([Relayed] -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
Bool -> STM s ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM s ()) -> ([Relayed] -> Bool) -> [Relayed] -> STM s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2) (Int -> Bool) -> ([Relayed] -> Int) -> [Relayed] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Relayed] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock, [Relayed])
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) EnvPeer (IOSim s)
holder ((NodeVsEnvConnection (IOSim s)
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s (Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock, [Relayed])
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_holderConn -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
1
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
(,) (Point LeiosTestBlock
-> [Relayed] -> (Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock)
-> IOSim s ([Relayed] -> (Point LeiosTestBlock, [Relayed]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
forall s.
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
awaitTip NodeUnderTest (IOSim s)
node (LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint LeiosTestBlock
certifyingFetched) IOSim s ([Relayed] -> (Point LeiosTestBlock, [Relayed]))
-> IOSim s [Relayed] -> IOSim s (Point LeiosTestBlock, [Relayed])
forall a b. IOSim s (a -> b) -> IOSim s a -> IOSim s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Listener s -> Int -> IOSim s [Relayed]
forall s. Listener s -> Int -> IOSim s [Relayed]
relayedBy Listener s
heard Int
2
nodeFetchesCertified :: IOSim s [Acquired]
nodeFetchesCertified :: forall s. IOSim s [Acquired]
nodeFetchesCertified = (NodeUnderTest (IOSim s) -> IOSim s [Acquired])
-> IOSim s [Acquired]
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s [Acquired])
-> IOSim s [Acquired])
-> (NodeUnderTest (IOSim s) -> IOSim s [Acquired])
-> IOSim s [Acquired]
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
next <- LeiosAcquisitions (IOSim s)
-> IOSim s (STM (IOSim s) LeiosAcquisition)
forall (m :: * -> *).
LeiosAcquisitions m -> m (STM m LeiosAcquisition)
subscribeLeiosAcquisitions (NodeUnderTest (IOSim s) -> LeiosAcquisitions (IOSim s)
forall (m :: * -> *). NodeUnderTest m -> LeiosAcquisitions m
nodeLeiosAcquisitions NodeUnderTest (IOSim s)
node)
notifications <- newTQueueIO
atomically $ writeTQueue notifications (MsgLeiosBlockAnnouncement (ltbHeader announcingFetched))
let envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer =
[ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
[ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
scriptedChainSyncServer ([ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
())
-> [ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$
Header LeiosTestBlock -> ChainSyncStep
SendRollForward (Header LeiosTestBlock -> ChainSyncStep)
-> (LeiosTestBlock -> Header LeiosTestBlock)
-> LeiosTestBlock
-> ChainSyncStep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeiosTestBlock -> Header LeiosTestBlock
ltbHeader (LeiosTestBlock -> ChainSyncStep)
-> [LeiosTestBlock] -> [ChainSyncStep]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
_conn ->
Int -> IOSim s Acquired -> IOSim s [Acquired]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
2 (IOSim s Acquired -> IOSim s [Acquired])
-> IOSim s Acquired -> IOSim s [Acquired]
forall a b. (a -> b) -> a -> b
$ LeiosAcquisition -> Acquired
acquiredOf (LeiosAcquisition -> Acquired)
-> IOSim s LeiosAcquisition -> IOSim s Acquired
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM (IOSim s) LeiosAcquisition -> IOSim s LeiosAcquisition
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) LeiosAcquisition
STM s LeiosAcquisition
next
nodeFetchesRolledForward :: IOSim s ([Acquired], [Relayed])
nodeFetchesRolledForward :: forall s. IOSim s ([Acquired], [Relayed])
nodeFetchesRolledForward = (NodeUnderTest (IOSim s) -> IOSim s ([Acquired], [Relayed]))
-> IOSim s ([Acquired], [Relayed])
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s ([Acquired], [Relayed]))
-> IOSim s ([Acquired], [Relayed]))
-> (NodeUnderTest (IOSim s) -> IOSim s ([Acquired], [Relayed]))
-> IOSim s ([Acquired], [Relayed])
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
next <- LeiosAcquisitions (IOSim s)
-> IOSim s (STM (IOSim s) LeiosAcquisition)
forall (m :: * -> *).
LeiosAcquisitions m -> m (STM m LeiosAcquisition)
subscribeLeiosAcquisitions (NodeUnderTest (IOSim s) -> LeiosAcquisitions (IOSim s)
forall (m :: * -> *). NodeUnderTest m -> LeiosAcquisitions m
nodeLeiosAcquisitions NodeUnderTest (IOSim s)
node)
listener <- newListener node
let envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer =
[ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
[ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
scriptedChainSyncServer ([ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
())
-> [ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$
Header LeiosTestBlock -> ChainSyncStep
SendRollForward (Header LeiosTestBlock -> ChainSyncStep)
-> (LeiosTestBlock -> Header LeiosTestBlock)
-> LeiosTestBlock
-> ChainSyncStep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeiosTestBlock -> Header LeiosTestBlock
ltbHeader (LeiosTestBlock -> ChainSyncStep)
-> [LeiosTestBlock] -> [ChainSyncStep]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = \Channel (IOSim s) ByteString
_chan -> STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) ()
forall a. STM (IOSim s) a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = (Channel (IOSim s) ByteString -> IOSim s ())
-> Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. a -> Maybe a
Just (Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
forall s. Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
lsNotifyClient Listener s
listener)
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = (Channel (IOSim s) ByteString -> IOSim s ())
-> Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. a -> Maybe a
Just (Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
forall s. Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
lsFetchClient Listener s
listener)
}
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
_conn -> do
acquired <- Int -> IOSim s Acquired -> IOSim s [Acquired]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
2 (IOSim s Acquired -> IOSim s [Acquired])
-> IOSim s Acquired -> IOSim s [Acquired]
forall a b. (a -> b) -> a -> b
$ LeiosAcquisition -> Acquired
acquiredOf (LeiosAcquisition -> Acquired)
-> IOSim s LeiosAcquisition -> IOSim s Acquired
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM (IOSim s) LeiosAcquisition -> IOSim s LeiosAcquisition
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) LeiosAcquisition
STM s LeiosAcquisition
next
relays <- relayedBy listener 3
pure (acquired, relays)
nodeRecordsJumperOffers :: IOSim s [Bool]
nodeRecordsJumperOffers :: forall s. IOSim s [Bool]
nodeRecordsJumperOffers = SlotNo
-> (NodeUnderTest (IOSim s) -> IOSim s [Bool]) -> IOSim s [Bool]
forall s a.
SlotNo -> (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withJumpingNode SlotNo
1 ((NodeUnderTest (IOSim s) -> IOSim s [Bool]) -> IOSim s [Bool])
-> (NodeUnderTest (IOSim s) -> IOSim s [Bool]) -> IOSim s [Bool]
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
leaderChain <- [LeiosTestBlock] -> IOSim s (EnvChain (IOSim s))
forall s. [LeiosTestBlock] -> IOSim s (EnvChain (IOSim s))
newEnvChain [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
jumperChain <- newEnvChain longer
withNodeVsEnvConnection node (PeerAddr 1) (servingChain node leaderChain) $ \NodeVsEnvConnection (IOSim s)
_conn -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
3
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Bool])
-> IOSim s [Bool]
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) (NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
servingChain NodeUnderTest (IOSim s)
node EnvChain (IOSim s)
jumperChain) ((NodeVsEnvConnection (IOSim s) -> IOSim s [Bool])
-> IOSim s [Bool])
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Bool])
-> IOSim s [Bool]
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_conn -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
1
EnvChain (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall s. EnvChain (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
serveChain EnvChain (IOSim s)
leaderChain [LeiosTestBlock]
longer
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
2
(PeerAddr -> IOSim s Bool) -> [PeerAddr] -> IOSim s [Bool]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s Bool
forall s. NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s Bool
offersFetched NodeUnderTest (IOSim s)
node) [Int -> PeerAddr
PeerAddr Int
1, Int -> PeerAddr
PeerAddr Int
2]
where
longer :: [LeiosTestBlock]
longer = [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched, LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock LeiosTestBlock
certifyingFetched]
jumpedChain :: [LeiosTestBlock]
jumpedChain :: [LeiosTestBlock]
jumpedChain = [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched, LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock LeiosTestBlock
certifyingFetched]
nodeFetchesFromJumper :: IOSim s (Point LeiosTestBlock)
nodeFetchesFromJumper :: forall s. IOSim s (Point LeiosTestBlock)
nodeFetchesFromJumper = SlotNo
-> (NodeUnderTest (IOSim s) -> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock)
forall s a.
SlotNo -> (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withJumpingNode SlotNo
1 ((NodeUnderTest (IOSim s) -> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock))
-> (NodeUnderTest (IOSim s) -> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
leaderChain <- [LeiosTestBlock] -> IOSim s (EnvChain (IOSim s))
forall s. [LeiosTestBlock] -> IOSim s (EnvChain (IOSim s))
newEnvChain [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
jumperChain <- newEnvChain jumpedChain
let jumper = (NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
servingChain NodeUnderTest (IOSim s)
node EnvChain (IOSim s)
jumperChain){epLeiosFetchServer = servingFetched node}
withNodeVsEnvConnection node (PeerAddr 1) (servingChain node leaderChain) $ \NodeVsEnvConnection (IOSim s)
_conn -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
3
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock)
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) EnvPeer (IOSim s)
jumper ((NodeVsEnvConnection (IOSim s) -> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock))
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_conn -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
1
EnvChain (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall s. EnvChain (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
serveChain EnvChain (IOSim s)
leaderChain [LeiosTestBlock]
jumpedChain
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
2
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock]
jumpedChain
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
forall s.
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
awaitTip NodeUnderTest (IOSim s)
node ([LeiosTestBlock] -> Point LeiosTestBlock
lastPoint [LeiosTestBlock]
jumpedChain)
nodeFetchesFromJumperInSteps :: IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
nodeFetchesFromJumperInSteps :: forall s. IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
nodeFetchesFromJumperInSteps = SlotNo
-> (NodeUnderTest (IOSim s)
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
forall s a.
SlotNo -> (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withJumpingNode SlotNo
1 ((NodeUnderTest (IOSim s)
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> (NodeUnderTest (IOSim s)
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
leaderChain <- [LeiosTestBlock] -> IOSim s (EnvChain (IOSim s))
forall s. [LeiosTestBlock] -> IOSim s (EnvChain (IOSim s))
newEnvChain (Int -> [LeiosTestBlock] -> [LeiosTestBlock]
forall a. Int -> [a] -> [a]
take Int
1 [LeiosTestBlock]
jumpedChain)
jumperChain <- newEnvChain jumpedChain
let jumper = (NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
servingChain NodeUnderTest (IOSim s)
node EnvChain (IOSim s)
jumperChain){epLeiosFetchServer = servingFetched node}
withNodeVsEnvConnection node (PeerAddr 1) (servingChain node leaderChain) $ \NodeVsEnvConnection (IOSim s)
_conn -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
3
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) EnvPeer (IOSim s)
jumper ((NodeVsEnvConnection (IOSim s)
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock))
-> IOSim s ([WithOrigin SlotNo], Point LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_conn -> do
reached <- [Int]
-> (Int -> IOSim s (WithOrigin SlotNo))
-> IOSim s [WithOrigin SlotNo]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Int
2, Int
3] ((Int -> IOSim s (WithOrigin SlotNo))
-> IOSim s [WithOrigin SlotNo])
-> (Int -> IOSim s (WithOrigin SlotNo))
-> IOSim s [WithOrigin SlotNo]
forall a b. (a -> b) -> a -> b
$ \Int
n -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
1
EnvChain (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall s. EnvChain (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
serveChain EnvChain (IOSim s)
leaderChain (Int -> [LeiosTestBlock] -> [LeiosTestBlock]
forall a. Int -> [a] -> [a]
take Int
n [LeiosTestBlock]
jumpedChain)
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
2
NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s (WithOrigin SlotNo)
forall s.
NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s (WithOrigin SlotNo)
jumpedThrough NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2)
addBlocks node jumpedChain
(,) reached <$> awaitTip node (lastPoint jumpedChain)
jumpedThrough :: NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s (WithOrigin SlotNo)
jumpedThrough :: forall s.
NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s (WithOrigin SlotNo)
jumpedThrough NodeUnderTest (IOSim s)
node PeerAddr
addr = STM (IOSim s) (WithOrigin SlotNo) -> IOSim s (WithOrigin SlotNo)
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
IOLike.atomically (STM (IOSim s) (WithOrigin SlotNo) -> IOSim s (WithOrigin SlotNo))
-> STM (IOSim s) (WithOrigin SlotNo) -> IOSim s (WithOrigin SlotNo)
forall a b. (a -> b) -> a -> b
$ do
peers <- StrictTVar
(IOSim s)
(Map
(LeiosPeerLifetimeId (ConnectionId PeerAddr))
(LeiosFetchPeer (IOSim s) LeiosTestBlock))
-> STM
(IOSim s)
(Map
(LeiosPeerLifetimeId (ConnectionId PeerAddr))
(LeiosFetchPeer (IOSim s) LeiosTestBlock))
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
IOLike.readTVar (LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
-> StrictTVar
(IOSim s)
(Map
(LeiosPeerLifetimeId (ConnectionId PeerAddr))
(LeiosFetchPeer (IOSim s) LeiosTestBlock))
forall (m :: * -> *) peer blk.
LeiosFetchKernel m peer blk
-> StrictTVar
m (Map (LeiosPeerLifetimeId peer) (LeiosFetchPeer m blk))
lfkPeers (NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
-> LeiosFetchKernel
(IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk
-> LeiosFetchKernel m (ConnectionId addrNTN) blk
getLeiosFetchKernel (NodeUnderTest (IOSim s)
-> NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
forall (m :: * -> *).
NodeUnderTest m
-> NodeKernel m PeerAddr (ConnectionId ()) LeiosTestBlock
nodeKernel NodeUnderTest (IOSim s)
node)))
case [peer | (MkLeiosPeerLifetimeId connId _, peer) <- Map.toList peers, remoteAddress connId == addr] of
[] -> WithOrigin SlotNo -> STM s (WithOrigin SlotNo)
forall a. a -> STM s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure WithOrigin SlotNo
forall t. WithOrigin t
Origin
LeiosFetchPeer (IOSim s) LeiosTestBlock
peer : [LeiosFetchPeer (IOSim s) LeiosTestBlock]
_ -> Point LeiosTestBlock -> WithOrigin SlotNo
forall {k} (block :: k). Point block -> WithOrigin SlotNo
pointSlot (Point LeiosTestBlock -> WithOrigin SlotNo)
-> STM s (Point LeiosTestBlock) -> STM s (WithOrigin SlotNo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictTVar (IOSim s) (Point LeiosTestBlock)
-> STM (IOSim s) (Point LeiosTestBlock)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
IOLike.readTVar (LeiosFetchPeer (IOSim s) LeiosTestBlock
-> StrictTVar (IOSim s) (Point LeiosTestBlock)
forall (m :: * -> *) blk.
LeiosFetchPeer m blk -> StrictTVar m (Point blk)
lfpJumpedThrough LeiosFetchPeer (IOSim s) LeiosTestBlock
peer)
nodeIgnoresPrunedOffer :: IOSim s [SlotNo]
nodeIgnoresPrunedOffer :: forall s. IOSim s [SlotNo]
nodeIgnoresPrunedOffer = (NodeUnderTest (IOSim s) -> IOSim s [SlotNo]) -> IOSim s [SlotNo]
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s [SlotNo]) -> IOSim s [SlotNo])
-> (NodeUnderTest (IOSim s) -> IOSim s [SlotNo])
-> IOSim s [SlotNo]
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
let kernel :: LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
kernel = NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
-> LeiosFetchKernel
(IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk
-> LeiosFetchKernel m (ConnectionId addrNTN) blk
getLeiosFetchKernel (NodeUnderTest (IOSim s)
-> NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
forall (m :: * -> *).
NodeUnderTest m
-> NodeKernel m PeerAddr (ConnectionId ()) LeiosTestBlock
nodeKernel NodeUnderTest (IOSim s)
node)
offer :: PeerOffer
offer =
MkPeerOffer
{ poEbBounds :: StrictMaybe (LeiosEbByteSizes 'SizeLimit)
poEbBounds = StrictMaybe (LeiosEbByteSizes 'SizeLimit)
forall a. StrictMaybe a
SNothing
, poOffered :: OfferedHalves
poOffered = OfferedHalves
OfferedClosure
}
peer :: ConnectionId PeerAddr
peer = PeerAddr -> PeerAddr -> ConnectionId PeerAddr
forall addr. addr -> addr -> ConnectionId addr
ConnectionId (Int -> PeerAddr
PeerAddr Int
0) (Int -> PeerAddr
PeerAddr Int
1)
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
IOLike.atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) SlotNo -> SlotNo -> STM (IOSim s) ()
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
StrictTVar m a -> a -> STM m ()
IOLike.writeTVar (LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
-> StrictTVar (IOSim s) SlotNo
forall (m :: * -> *) peer blk.
LeiosFetchKernel m peer blk -> StrictTVar m SlotNo
lfkPrunedSlot LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
kernel) (Word64 -> SlotNo
SlotNo Word64
5)
LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
-> ConnectionId PeerAddr
-> IsBigLedgerPeer
-> (LeiosPeerLifetimeId (ConnectionId PeerAddr)
-> LeiosFetchPeer (IOSim s) LeiosTestBlock -> IOSim s [SlotNo])
-> IOSim s [SlotNo]
forall (m :: * -> *) peer blk a.
(IOLike m, Ord peer) =>
LeiosFetchKernel m peer blk
-> peer
-> IsBigLedgerPeer
-> (LeiosPeerLifetimeId peer -> LeiosFetchPeer m blk -> m a)
-> m a
withLeiosFetchPeer LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
kernel ConnectionId PeerAddr
peer IsBigLedgerPeer
IsNotBigLedgerPeer ((LeiosPeerLifetimeId (ConnectionId PeerAddr)
-> LeiosFetchPeer (IOSim s) LeiosTestBlock -> IOSim s [SlotNo])
-> IOSim s [SlotNo])
-> (LeiosPeerLifetimeId (ConnectionId PeerAddr)
-> LeiosFetchPeer (IOSim s) LeiosTestBlock -> IOSim s [SlotNo])
-> IOSim s [SlotNo]
forall a b. (a -> b) -> a -> b
$ \LeiosPeerLifetimeId (ConnectionId PeerAddr)
_lifetimeId LeiosFetchPeer (IOSim s) LeiosTestBlock
peerVars -> do
[SlotNo] -> (SlotNo -> IOSim s ()) -> IOSim s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Word64 -> SlotNo
SlotNo Word64
4, Word64 -> SlotNo
SlotNo Word64
5] ((SlotNo -> IOSim s ()) -> IOSim s ())
-> (SlotNo -> IOSim s ()) -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ \SlotNo
slot ->
LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
-> LeiosFetchPeer (IOSim s) LeiosTestBlock
-> LeiosPoint
-> PeerOffer
-> IOSim s ()
forall (m :: * -> *) peer blk.
IOLike m =>
LeiosFetchKernel m peer blk
-> LeiosFetchPeer m blk -> LeiosPoint -> PeerOffer -> m ()
recordLeiosOffer LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
kernel LeiosFetchPeer (IOSim s) LeiosTestBlock
peerVars (SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint SlotNo
slot (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb)) PeerOffer
offer
(LeiosPoint -> SlotNo) -> [LeiosPoint] -> [SlotNo]
forall a b. (a -> b) -> [a] -> [b]
map LeiosPoint -> SlotNo
pointSlotNo ([LeiosPoint] -> [SlotNo])
-> (Map LeiosPoint PeerOffer -> [LeiosPoint])
-> Map LeiosPoint PeerOffer
-> [SlotNo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map LeiosPoint PeerOffer -> [LeiosPoint]
forall k a. Map k a -> [k]
Map.keys (Map LeiosPoint PeerOffer -> [SlotNo])
-> IOSim s (Map LeiosPoint PeerOffer) -> IOSim s [SlotNo]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictTVar (IOSim s) (Map LeiosPoint PeerOffer)
-> IOSim s (Map LeiosPoint PeerOffer)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> m a
IOLike.readTVarIO (LeiosFetchPeer (IOSim s) LeiosTestBlock
-> StrictTVar (IOSim s) (Map LeiosPoint PeerOffer)
forall (m :: * -> *) blk.
LeiosFetchPeer m blk -> StrictTVar m (Map LeiosPoint PeerOffer)
lfpOfferings LeiosFetchPeer (IOSim s) LeiosTestBlock
peerVars)
nodeDisconnectsDoubleCertifier :: IOSim s (Maybe (EndorserBlockHash, EndorserBlockHash))
nodeDisconnectsDoubleCertifier :: forall s.
IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
nodeDisconnectsDoubleCertifier = (NodeUnderTest (IOSim s)
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s)
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> (NodeUnderTest (IOSim s)
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
let envPeer :: EnvPeer (IOSim s)
envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer =
[ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
[ChainSyncStep]
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
scriptedChainSyncServer
[ Header LeiosTestBlock -> ChainSyncStep
SendRollForward (LeiosTestBlock -> Header LeiosTestBlock
ltbHeader LeiosTestBlock
announcingFetched)
, Header LeiosTestBlock -> ChainSyncStep
SendRollForward (LeiosTestBlock -> Header LeiosTestBlock
ltbHeader LeiosTestBlock
certifyingFetched)
, Point LeiosTestBlock -> Tip LeiosTestBlock -> ChainSyncStep
SendRollBackward Point LeiosTestBlock
forall {k} (block :: k). Point block
GenesisPoint Tip LeiosTestBlock
forall {k} (b :: k). Tip b
TipGenesis
, Header LeiosTestBlock -> ChainSyncStep
SendRollForward (LeiosTestBlock -> Header LeiosTestBlock
ltbHeader LeiosTestBlock
announcingOther)
, Header LeiosTestBlock -> ChainSyncStep
SendRollForward (LeiosTestBlock -> Header LeiosTestBlock
ltbHeader (LeiosTestBlock -> LeiosTestBlock
certifying LeiosTestBlock
announcingOther))
]
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = \Channel (IOSim s) ByteString
_chan -> STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) ()
forall a. STM (IOSim s) a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
silentLeiosFetchServer NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s)
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
1) EnvPeer (IOSim s)
envPeer ((NodeVsEnvConnection (IOSim s)
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> (NodeVsEnvConnection (IOSim s)
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)))
-> IOSim
s
(Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences))
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
conn -> do
chainSync <-
IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
-> (STM s (Either SomeException NodeToNodeInitiatorResult)
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (IOError
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall e a. Exception e => e -> IOSim s a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO (IOError
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> IOError
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a b. (a -> b) -> a -> b
$ [Char] -> IOError
userError [Char]
"the node does not run a ChainSync client") STM s (Either SomeException NodeToNodeInitiatorResult)
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a b. (a -> b) -> a -> b
$
MiniProtocolNum
-> Map
MiniProtocolNum
(STM s (Either SomeException NodeToNodeInitiatorResult))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup MiniProtocolNum
chainSyncMiniProtocolNum (NodeVsEnvConnection (IOSim s)
-> Map
MiniProtocolNum
(STM (IOSim s) (Either SomeException NodeToNodeInitiatorResult))
forall (m :: * -> *).
NodeVsEnvConnection m
-> Map
MiniProtocolNum
(STM m (Either SomeException NodeToNodeInitiatorResult))
connNodeInitiators NodeVsEnvConnection (IOSim s)
conn)
atomically chainSync <&> \case
Left SomeException
e
| Just (ExnLeiosTwoCertificationClaims ElectionId
_elId Hash HASH EraIndependentEbReferences
claimed Hash HASH EraIndependentEbReferences
claimedAgain) <- SomeException -> Maybe ExnLeiosTwoCertificationClaims
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e ->
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
-> Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
forall a. a -> Maybe a
Just (Hash HASH EraIndependentEbReferences
claimed, Hash HASH EraIndependentEbReferences
claimedAgain)
Either SomeException NodeToNodeInitiatorResult
_ -> Maybe
(Hash HASH EraIndependentEbReferences,
Hash HASH EraIndependentEbReferences)
forall a. Maybe a
Nothing
nodeFetchesAfterPruningEarlier :: IOSim s ([Acquired], [Relayed])
nodeFetchesAfterPruningEarlier :: forall s. IOSim s ([Acquired], [Relayed])
nodeFetchesAfterPruningEarlier = (NodeUnderTest (IOSim s) -> IOSim s ([Acquired], [Relayed]))
-> IOSim s ([Acquired], [Relayed])
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s ([Acquired], [Relayed]))
-> IOSim s ([Acquired], [Relayed]))
-> (NodeUnderTest (IOSim s) -> IOSim s ([Acquired], [Relayed]))
-> IOSim s ([Acquired], [Relayed])
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
next <- LeiosAcquisitions (IOSim s)
-> IOSim s (STM (IOSim s) LeiosAcquisition)
forall (m :: * -> *).
LeiosAcquisitions m -> m (STM m LeiosAcquisition)
subscribeLeiosAcquisitions (NodeUnderTest (IOSim s) -> LeiosAcquisitions (IOSim s)
forall (m :: * -> *). NodeUnderTest m -> LeiosAcquisitions m
nodeLeiosAcquisitions NodeUnderTest (IOSim s)
node)
listener <- newListener node
notifications <- newTQueueIO
atomically $
mapM_
(writeTQueue notifications . MsgLeiosBlockAnnouncement . ltbHeader)
[announcingFetched, reannouncingFetched]
let envPeer =
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Listener s
-> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Listener s
-> EnvPeer (IOSim s)
holdingFetchedListening NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications Listener s
listener
threadDelay 20
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
_conn -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) [Relayed] -> STM (IOSim s) [Relayed]
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar (Listener s -> StrictTVar (IOSim s) [Relayed]
forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed Listener s
listener) STM (IOSim s) [Relayed]
-> ([Relayed] -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
Bool -> STM s ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM s ()) -> ([Relayed] -> Bool) -> [Relayed] -> STM s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2) (Int -> Bool) -> ([Relayed] -> Int) -> [Relayed] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Relayed] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node ([LeiosTestBlock] -> IOSim s ()) -> [LeiosTestBlock] -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ LeiosTestBlock
announcingFetched LeiosTestBlock -> [LeiosTestBlock] -> [LeiosTestBlock]
forall a. a -> [a] -> [a]
: Int -> [LeiosTestBlock] -> [LeiosTestBlock]
forall a. Int -> [a] -> [a]
take Int
11 ((LeiosTestBlock -> LeiosTestBlock)
-> LeiosTestBlock -> [LeiosTestBlock]
forall a. (a -> a) -> a -> [a]
iterate LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock LeiosTestBlock
reannouncingFetched)
NodeUnderTest (IOSim s) -> SlotNo -> IOSim s ()
forall s. NodeUnderTest (IOSim s) -> SlotNo -> IOSim s ()
awaitPrunedPast NodeUnderTest (IOSim s)
node (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingFetched)
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ())
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
-> STM (IOSim s) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
(StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTQueue m a -> a -> STM m ()
writeTQueue StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications)
[ LeiosPoint
-> Word32
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Word32
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockOffer LeiosPoint
refocusedPoint (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb)
, LeiosPoint
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockTxsOffer LeiosPoint
refocusedPoint
]
(,) ([Acquired] -> [Relayed] -> ([Acquired], [Relayed]))
-> IOSim s [Acquired]
-> IOSim s ([Relayed] -> ([Acquired], [Relayed]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> IOSim s Acquired -> IOSim s [Acquired]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
2 (LeiosAcquisition -> Acquired
acquiredOf (LeiosAcquisition -> Acquired)
-> IOSim s LeiosAcquisition -> IOSim s Acquired
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM (IOSim s) LeiosAcquisition -> IOSim s LeiosAcquisition
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) LeiosAcquisition
STM s LeiosAcquisition
next) IOSim s ([Relayed] -> ([Acquired], [Relayed]))
-> IOSim s [Relayed] -> IOSim s ([Acquired], [Relayed])
forall a b. IOSim s (a -> b) -> IOSim s a -> IOSim s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Listener s -> Int -> IOSim s [Relayed]
forall s. Listener s -> Int -> IOSim s [Relayed]
relayedBy Listener s
listener Int
4
relayedFetchedAfterRival :: [Relayed]
relayedFetchedAfterRival :: [Relayed]
relayedFetchedAfterRival = Relayed
RelayedAnnouncement Relayed -> [Relayed] -> [Relayed]
forall a. a -> [a] -> [a]
: LeiosPoint -> [Relayed]
relayedFetchedAt LeiosPoint
fetchedPoint
data CertifyingArrival = CertifyingAfterAnnouncing | CertifyingBeforeAnnouncing
deriving (Int -> CertifyingArrival -> [Char] -> [Char]
[CertifyingArrival] -> [Char] -> [Char]
CertifyingArrival -> [Char]
(Int -> CertifyingArrival -> [Char] -> [Char])
-> (CertifyingArrival -> [Char])
-> ([CertifyingArrival] -> [Char] -> [Char])
-> Show CertifyingArrival
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> CertifyingArrival -> [Char] -> [Char]
showsPrec :: Int -> CertifyingArrival -> [Char] -> [Char]
$cshow :: CertifyingArrival -> [Char]
show :: CertifyingArrival -> [Char]
$cshowList :: [CertifyingArrival] -> [Char] -> [Char]
showList :: [CertifyingArrival] -> [Char] -> [Char]
Show, Int -> CertifyingArrival
CertifyingArrival -> Int
CertifyingArrival -> [CertifyingArrival]
CertifyingArrival -> CertifyingArrival
CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
CertifyingArrival
-> CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
(CertifyingArrival -> CertifyingArrival)
-> (CertifyingArrival -> CertifyingArrival)
-> (Int -> CertifyingArrival)
-> (CertifyingArrival -> Int)
-> (CertifyingArrival -> [CertifyingArrival])
-> (CertifyingArrival -> CertifyingArrival -> [CertifyingArrival])
-> (CertifyingArrival -> CertifyingArrival -> [CertifyingArrival])
-> (CertifyingArrival
-> CertifyingArrival -> CertifyingArrival -> [CertifyingArrival])
-> Enum CertifyingArrival
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: CertifyingArrival -> CertifyingArrival
succ :: CertifyingArrival -> CertifyingArrival
$cpred :: CertifyingArrival -> CertifyingArrival
pred :: CertifyingArrival -> CertifyingArrival
$ctoEnum :: Int -> CertifyingArrival
toEnum :: Int -> CertifyingArrival
$cfromEnum :: CertifyingArrival -> Int
fromEnum :: CertifyingArrival -> Int
$cenumFrom :: CertifyingArrival -> [CertifyingArrival]
enumFrom :: CertifyingArrival -> [CertifyingArrival]
$cenumFromThen :: CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
enumFromThen :: CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
$cenumFromTo :: CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
enumFromTo :: CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
$cenumFromThenTo :: CertifyingArrival
-> CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
enumFromThenTo :: CertifyingArrival
-> CertifyingArrival -> CertifyingArrival -> [CertifyingArrival]
Enum, CertifyingArrival
CertifyingArrival -> CertifyingArrival -> Bounded CertifyingArrival
forall a. a -> a -> Bounded a
$cminBound :: CertifyingArrival
minBound :: CertifyingArrival
$cmaxBound :: CertifyingArrival
maxBound :: CertifyingArrival
Bounded)
nodeSelectsCertifiedRival ::
CertifyingArrival -> IOSim s (Bool, Point LeiosTestBlock, [Relayed])
nodeSelectsCertifiedRival :: forall s.
CertifyingArrival
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed])
nodeSelectsCertifiedRival CertifyingArrival
arrival = (NodeUnderTest (IOSim s)
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed]))
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed])
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s)
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed]))
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed]))
-> (NodeUnderTest (IOSim s)
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed]))
-> IOSim s (Bool, Point LeiosTestBlock, [Relayed])
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
listener <- NodeUnderTest (IOSim s) -> IOSim s (Listener s)
forall s. NodeUnderTest (IOSim s) -> IOSim s (Listener s)
newListener NodeUnderTest (IOSim s)
node
notifications <- newTQueueIO
atomically $
mapM_ (writeTQueue notifications) $
MsgLeiosBlockAnnouncement (ltbHeader announcingOther)
: announcingAndOffering fetchedEb announcingFetched
let envPeer =
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Listener s
-> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Listener s
-> EnvPeer (IOSim s)
holdingFetchedListening NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications Listener s
listener
threadDelay 20
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
_conn -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) [Relayed] -> STM (IOSim s) [Relayed]
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar (Listener s -> StrictTVar (IOSim s) [Relayed]
forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed Listener s
listener) STM (IOSim s) [Relayed]
-> ([Relayed] -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
Bool -> STM s ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM s ()) -> ([Relayed] -> Bool) -> [Relayed] -> STM s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
2) (Int -> Bool) -> ([Relayed] -> Int) -> [Relayed] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Relayed] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
rivalFocused <-
LeiosPoint
-> LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr))
-> Bool
forall peer. LeiosPoint -> LeiosOutstanding peer -> Bool
isFocusedPoint (SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingOther) Hash HASH EraIndependentEbReferences
otherEbHash) (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr))
-> Bool)
-> IOSim
s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
-> IOSim s Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NodeUnderTest (IOSim s)
-> IOSim
s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
forall s.
NodeUnderTest (IOSim s)
-> IOSim
s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
readOutstanding NodeUnderTest (IOSim s)
node
case arrival of
CertifyingArrival
CertifyingAfterAnnouncing -> NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
CertifyingArrival
CertifyingBeforeAnnouncing -> do
NodeUnderTest (IOSim s)
-> WithOrigin LeiosTestBlock -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m
-> WithOrigin LeiosTestBlock -> [LeiosTestBlock] -> m ()
addBlocksAfter NodeUnderTest (IOSim s)
node (LeiosTestBlock -> WithOrigin LeiosTestBlock
forall t. t -> WithOrigin t
NotOrigin LeiosTestBlock
announcingFetched) [LeiosTestBlock
certifyingFetched]
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock
announcingFetched]
(,,) rivalFocused <$> awaitTip node (blockPoint certifyingFetched) <*> relayedBy listener 2
nodeFetchesAtOfferedSize :: IOSim s [Acquired]
nodeFetchesAtOfferedSize :: forall s. IOSim s [Acquired]
nodeFetchesAtOfferedSize = (NodeUnderTest (IOSim s) -> IOSim s [Acquired])
-> IOSim s [Acquired]
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s [Acquired])
-> IOSim s [Acquired])
-> (NodeUnderTest (IOSim s) -> IOSim s [Acquired])
-> IOSim s [Acquired]
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
next <- LeiosAcquisitions (IOSim s)
-> IOSim s (STM (IOSim s) LeiosAcquisition)
forall (m :: * -> *).
LeiosAcquisitions m -> m (STM m LeiosAcquisition)
subscribeLeiosAcquisitions (NodeUnderTest (IOSim s) -> LeiosAcquisitions (IOSim s)
forall (m :: * -> *). NodeUnderTest m -> LeiosAcquisitions m
nodeLeiosAcquisitions NodeUnderTest (IOSim s)
node)
notifications <- newTQueueIO
atomically $
mapM_ (writeTQueue notifications) $
announcingAndOffering fetchedEb (misstating announcingFetched)
let envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
_conn ->
Int -> IOSim s Acquired -> IOSim s [Acquired]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
2 (IOSim s Acquired -> IOSim s [Acquired])
-> IOSim s Acquired -> IOSim s [Acquired]
forall a b. (a -> b) -> a -> b
$ LeiosAcquisition -> Acquired
acquiredOf (LeiosAcquisition -> Acquired)
-> IOSim s LeiosAcquisition -> IOSim s Acquired
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM (IOSim s) LeiosAcquisition -> IOSim s LeiosAcquisition
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) LeiosAcquisition
STM s LeiosAcquisition
next
nodeSelectsDespiteMisstatedSize :: IOSim s (Point LeiosTestBlock)
nodeSelectsDespiteMisstatedSize :: forall s. IOSim s (Point LeiosTestBlock)
nodeSelectsDespiteMisstatedSize = (NodeUnderTest (IOSim s) -> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock)
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock))
-> (NodeUnderTest (IOSim s) -> IOSim s (Point LeiosTestBlock))
-> IOSim s (Point LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
notifications <- IOSim
s
(StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle))
forall (m :: * -> *) a. MonadSTM m => m (StrictTQueue m a)
newTQueueIO
atomically $
mapM_ (writeTQueue notifications) $
MsgLeiosBlockAnnouncement (ltbHeader (misstating (successorLeiosBlock (firstLeiosBlock 7))))
: announcingAndOffering fetchedEb announcingFetched
let envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
threadDelay 20
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
_conn -> do
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
forall s.
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
awaitTip NodeUnderTest (IOSim s)
node (LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint LeiosTestBlock
certifyingFetched)
misstating :: LeiosTestBlock -> LeiosTestBlock
misstating :: LeiosTestBlock -> LeiosTestBlock
misstating =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb) (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
1)
prop_boundedEb :: Property
prop_boundedEb :: Property
prop_boundedEb =
Property -> Property
forall prop. Testable prop => prop -> Property
checkCoverage (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Gen (Int, Word32) -> ((Int, Word32) -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (Int, Word32)
genEvenEb (((Int, Word32) -> Property) -> Property)
-> ((Int, Word32) -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \(Int
count, Word32
size) ->
let ebAndTxs :: (EndorserBlock, Vector LeiosTx)
ebAndTxs@(EndorserBlock
eb, Vector LeiosTx
_txs) = Int -> Word32 -> (EndorserBlock, Vector LeiosTx)
evenEb Int
count Word32
size
in Double -> Bool -> [Char] -> Property -> Property
forall prop.
Testable prop =>
Double -> Bool -> [Char] -> prop -> Property
cover
Double
10
( Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
count Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* Word32
size Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
maxEbBodySize
Bool -> Bool -> Bool
&& EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
eb Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word32
maxEbBodySize
)
[Char]
"transactions totalling the most, in a body the ledger admits"
(Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$ IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty
(IO Property -> Property) -> IO Property -> Property
forall a b. (a -> b) -> a -> b
$ do
observed@(_acquired, failure) <- (forall s. IOSim s ([Acquired], Maybe [Char]))
-> IO ([Acquired], Maybe [Char])
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing ((EndorserBlock, Vector LeiosTx)
-> IOSim s ([Acquired], Maybe [Char])
forall s.
(EndorserBlock, Vector LeiosTx)
-> IOSim s ([Acquired], Maybe [Char])
nodeTakesEvenEb (EndorserBlock, Vector LeiosTx)
ebAndTxs)
pure $
tabulate "the client" [maybe "fetched it" (("failed: " <>) . takeWhile (/= ' ')) failure] $
observed === expectedBounded eb
genEvenEb :: Gen (Int, BytesSize)
genEvenEb :: Gen (Int, Word32)
genEvenEb = [Gen (Int, Word32)] -> Gen (Int, Word32)
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Gen (Int, Word32)
near, Gen (Int, Word32)
exact]
where
most :: Int
most = Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
maxEbBodySize :: Int
near :: Gen (Int, Word32)
near = do
count <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
1, Int
200)
let fitting = Int
most Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
count
size <- choose (max 1 (fitting - 2), fitting + 2)
pure (count, fromIntegral size)
exact :: Gen (Int, Word32)
exact = do
count <- [Int] -> Gen Int
forall a. HasCallStack => [a] -> Gen a
elements [Int
c | Int
c <- [Int
1 .. Int
200], Int
most Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0]
pure (count, fromIntegral (most `div` count))
evenEb :: Int -> BytesSize -> (EndorserBlock, V.Vector LeiosTx)
evenEb :: Int -> Word32 -> (EndorserBlock, Vector LeiosTx)
evenEb Int
count Word32
size = ([(TxHash, Word32)] -> EndorserBlock
mkEndorserBlock [(LeiosTx -> TxHash
hashLeiosTx LeiosTx
tx, Word32
size) | LeiosTx
tx <- Vector LeiosTx -> [LeiosTx]
forall a. Vector a -> [a]
V.toList Vector LeiosTx
txs], Vector LeiosTx
txs)
where
txs :: Vector LeiosTx
txs =
[LeiosTx] -> Vector LeiosTx
forall a. [a] -> Vector a
V.fromList
[ByteString -> LeiosTx
MkLeiosTx (Int -> Word8 -> ByteString
BS.replicate (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
size) (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i)) | Int
i <- [Int
0 .. Int
count Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]]
evenEbPoint :: EndorserBlock -> LeiosPoint
evenEbPoint :: EndorserBlock -> LeiosPoint
evenEbPoint EndorserBlock
eb = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint SlotNo
1 (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
eb)
expectedBounded :: EndorserBlock -> ([Acquired], Maybe String)
expectedBounded :: EndorserBlock -> ([Acquired], Maybe [Char])
expectedBounded EndorserBlock
eb
| Word32
bodySize Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
> Word32
maxEbBodySize =
([], [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just (ExnLeiosFetchInvalidReply -> [Char]
forall a. Show a => a -> [Char]
show (LeiosPoint -> Word32 -> Word32 -> ExnLeiosFetchInvalidReply
ExnLeiosBlockTooBig LeiosPoint
point Word32
bodySize Word32
maxEbBodySize)))
| Word64
closureSize Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
maxEbBodySize =
([], [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just (ExnLeiosFetchInvalidReply -> [Char]
forall a. Show a => a -> [Char]
show (LeiosPoint -> Word64 -> Word64 -> ExnLeiosFetchInvalidReply
ExnLeiosClosureTooBig LeiosPoint
point Word64
closureSize (Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
maxEbBodySize))))
| Bool
otherwise = ([LeiosPoint -> Acquired
AcquiredBody LeiosPoint
point, LeiosPoint -> Acquired
AcquiredClosure LeiosPoint
point], Maybe [Char]
forall a. Maybe a
Nothing)
where
point :: LeiosPoint
point = EndorserBlock -> LeiosPoint
evenEbPoint EndorserBlock
eb
bodySize :: Word32
bodySize = EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
eb
closureSize :: Word64
closureSize = [Word64] -> Word64
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
size | (TxHash
_txHash, Word32
size) <- EndorserBlock -> [(TxHash, Word32)]
endorserBlockReferences EndorserBlock
eb]
nodeTakesEvenEb :: (EndorserBlock, V.Vector LeiosTx) -> IOSim s ([Acquired], Maybe String)
nodeTakesEvenEb :: forall s.
(EndorserBlock, Vector LeiosTx)
-> IOSim s ([Acquired], Maybe [Char])
nodeTakesEvenEb (EndorserBlock
eb, Vector LeiosTx
txs) = (NodeUnderTest (IOSim s) -> IOSim s ([Acquired], Maybe [Char]))
-> IOSim s ([Acquired], Maybe [Char])
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s ([Acquired], Maybe [Char]))
-> IOSim s ([Acquired], Maybe [Char]))
-> (NodeUnderTest (IOSim s) -> IOSim s ([Acquired], Maybe [Char]))
-> IOSim s ([Acquired], Maybe [Char])
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
next <- LeiosAcquisitions (IOSim s)
-> IOSim s (STM (IOSim s) LeiosAcquisition)
forall (m :: * -> *).
LeiosAcquisitions m -> m (STM m LeiosAcquisition)
subscribeLeiosAcquisitions (NodeUnderTest (IOSim s) -> LeiosAcquisitions (IOSim s)
forall (m :: * -> *). NodeUnderTest m -> LeiosAcquisitions m
nodeLeiosAcquisitions NodeUnderTest (IOSim s)
node)
notifications <- newTQueueIO
let offered = Word32 -> Word32 -> Word32
forall a. Ord a => a -> a -> a
min Word32
maxEbBodySize (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
eb)
point = EndorserBlock -> LeiosPoint
evenEbPoint EndorserBlock
eb
announcing = Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
eb) Word32
offered (Word64 -> LeiosTestBlock
firstLeiosBlock Word64
0)
envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
serving EndorserBlock
eb Vector LeiosTx
txs NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
atomically $
mapM_
(writeTQueue notifications)
[ MsgLeiosBlockAnnouncement (ltbHeader announcing)
, MsgLeiosBlockOffer point offered
, MsgLeiosBlockTxsOffer point
]
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
conn -> do
client <-
IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
-> (STM s (Either SomeException NodeToNodeInitiatorResult)
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (IOError
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall e a. Exception e => e -> IOSim s a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO (IOError
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> IOError
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a b. (a -> b) -> a -> b
$ [Char] -> IOError
userError [Char]
"the node does not run a LeiosFetch client") STM s (Either SomeException NodeToNodeInitiatorResult)
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a b. (a -> b) -> a -> b
$
MiniProtocolNum
-> Map
MiniProtocolNum
(STM s (Either SomeException NodeToNodeInitiatorResult))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup MiniProtocolNum
leiosFetchMiniProtocolNum (NodeVsEnvConnection (IOSim s)
-> Map
MiniProtocolNum
(STM (IOSim s) (Either SomeException NodeToNodeInitiatorResult))
forall (m :: * -> *).
NodeVsEnvConnection m
-> Map
MiniProtocolNum
(STM m (Either SomeException NodeToNodeInitiatorResult))
connNodeInitiators NodeVsEnvConnection (IOSim s)
conn)
threadDelay relayHorizon
let drain [Acquired]
acquired =
STM (IOSim s) (Maybe Acquired) -> IOSim s (Maybe Acquired)
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically ((Acquired -> Maybe Acquired
forall a. a -> Maybe a
Just (Acquired -> Maybe Acquired)
-> (LeiosAcquisition -> Acquired)
-> LeiosAcquisition
-> Maybe Acquired
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeiosAcquisition -> Acquired
acquiredOf (LeiosAcquisition -> Maybe Acquired)
-> STM s LeiosAcquisition -> STM s (Maybe Acquired)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM s LeiosAcquisition
next) STM (IOSim s) (Maybe Acquired)
-> STM (IOSim s) (Maybe Acquired) -> STM (IOSim s) (Maybe Acquired)
forall a. STM (IOSim s) a -> STM (IOSim s) a -> STM (IOSim s) a
forall (m :: * -> *) a. MonadSTM m => STM m a -> STM m a -> STM m a
`orElse` Maybe Acquired -> STM s (Maybe Acquired)
forall a. a -> STM s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Acquired
forall a. Maybe a
Nothing)
IOSim s (Maybe Acquired)
-> (Maybe Acquired -> IOSim s [Acquired]) -> IOSim s [Acquired]
forall a b. IOSim s a -> (a -> IOSim s b) -> IOSim s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IOSim s [Acquired]
-> (Acquired -> IOSim s [Acquired])
-> Maybe Acquired
-> IOSim s [Acquired]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Acquired] -> IOSim s [Acquired]
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Acquired] -> [Acquired]
forall a. [a] -> [a]
reverse [Acquired]
acquired)) ([Acquired] -> IOSim s [Acquired]
drain ([Acquired] -> IOSim s [Acquired])
-> (Acquired -> [Acquired]) -> Acquired -> IOSim s [Acquired]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Acquired -> [Acquired] -> [Acquired]
forall a. a -> [a] -> [a]
: [Acquired]
acquired))
acquired <- drain []
failure <- atomically $ (either (Just . show) (const Nothing) <$> client) `orElse` pure Nothing
pure (acquired, failure)
betterChain :: [LeiosTestBlock]
betterChain :: [LeiosTestBlock]
betterChain = Int -> [LeiosTestBlock] -> [LeiosTestBlock]
forall a. Int -> [a] -> [a]
take Int
3 ([LeiosTestBlock] -> [LeiosTestBlock])
-> [LeiosTestBlock] -> [LeiosTestBlock]
forall a b. (a -> b) -> a -> b
$ (LeiosTestBlock -> LeiosTestBlock)
-> LeiosTestBlock -> [LeiosTestBlock]
forall a. (a -> a) -> a -> [a]
iterate LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock (Word64 -> LeiosTestBlock
firstLeiosBlock Word64
1)
forgottenChain :: [LeiosTestBlock]
forgottenChain :: [LeiosTestBlock]
forgottenChain = LeiosTestBlock
announcingFetched LeiosTestBlock -> [LeiosTestBlock] -> [LeiosTestBlock]
forall a. a -> [a] -> [a]
: Int -> [LeiosTestBlock] -> [LeiosTestBlock]
forall a. Int -> [a] -> [a]
take Int
3 ((LeiosTestBlock -> LeiosTestBlock)
-> LeiosTestBlock -> [LeiosTestBlock]
forall a. (a -> a) -> a -> [a]
iterate LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock LeiosTestBlock
certifyingFetched)
nodeReselectsForgotten ::
IOSim s ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
nodeReselectsForgotten :: forall s.
IOSim s ((Int, Bool), (Bool, Int, Point LeiosTestBlock, [Relayed]))
nodeReselectsForgotten = do
nodeDBs <- IOSim s (NodeDBs (StrictTMVar (IOSim s) MockFS))
forall (m :: * -> *).
MonadSTM m =>
m (NodeDBs (StrictTMVar m MockFS))
emptyNodeDBs
leiosDb <- newLeiosDBInMemory
beforeRestart <- withNodeOverDBs nodeDBs leiosDb $ \NodeUnderTest (IOSim s)
node -> do
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
20
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock
announcingFetched, LeiosTestBlock
certifyingFetched]
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock]
betterChain
(,) (Int -> Bool -> (Int, Bool))
-> IOSim s Int -> IOSim s (Bool -> (Int, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NodeUnderTest (IOSim s) -> IOSim s Int
forall {f :: * -> *}. MonadSTM f => NodeUnderTest f -> f Int
certifiedCount NodeUnderTest (IOSim s)
node IOSim s (Bool -> (Int, Bool))
-> IOSim s Bool -> IOSim s (Int, Bool)
forall a b. IOSim s (a -> b) -> IOSim s a -> IOSim s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> NodeUnderTest (IOSim s) -> LeiosTestBlock -> IOSim s Bool
forall {m :: * -> *}.
MonadSTM m =>
NodeUnderTest m -> LeiosTestBlock -> m Bool
holds NodeUnderTest (IOSim s)
node LeiosTestBlock
certifyingFetched
afterRestart <- withNodeOverDBs nodeDBs leiosDb $ \NodeUnderTest (IOSim s)
node -> do
forgotten <- Bool -> Bool
not (Bool -> Bool) -> IOSim s Bool -> IOSim s Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NodeUnderTest (IOSim s) -> LeiosTestBlock -> IOSim s Bool
forall {m :: * -> *}.
MonadSTM m =>
NodeUnderTest m -> LeiosTestBlock -> m Bool
holds NodeUnderTest (IOSim s)
node LeiosTestBlock
certifyingFetched
certifiedAtStart <- certifiedCount node
heardByRival <- newListener node
rivalNotifications <- newTQueueIO
holderNotifications <- newTQueueIO
atomically $ do
writeTQueue rivalNotifications (MsgLeiosBlockAnnouncement (ltbHeader announcingOther))
mapM_ (writeTQueue holderNotifications) (announcingAndOffering fetchedEb announcingFetched)
let rival =
(NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
listening NodeUnderTest (IOSim s)
node Listener s
heardByRival)
{ epLeiosNotifyServer = feedingLeiosNotifyServer node rivalNotifications
}
holder =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
holderNotifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
withNodeVsEnvConnection node (PeerAddr 1) rival $ \NodeVsEnvConnection (IOSim s)
_rivalConn -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) [Relayed] -> STM (IOSim s) [Relayed]
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar (Listener s -> StrictTVar (IOSim s) [Relayed]
forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed Listener s
heardByRival) STM (IOSim s) [Relayed]
-> ([Relayed] -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
Bool -> STM s ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM s ()) -> ([Relayed] -> Bool) -> [Relayed] -> STM s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Bool
not (Bool -> Bool) -> ([Relayed] -> Bool) -> [Relayed] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Relayed] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> IOSim s (Bool, Int, Point LeiosTestBlock, [Relayed])
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) EnvPeer (IOSim s)
holder ((NodeVsEnvConnection (IOSim s)
-> IOSim s (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> IOSim s (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> (NodeVsEnvConnection (IOSim s)
-> IOSim s (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> IOSim s (Bool, Int, Point LeiosTestBlock, [Relayed])
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_holderConn -> do
NodeUnderTest (IOSim s) -> [LeiosTestBlock] -> IOSim s ()
forall (m :: * -> *).
IOLike m =>
NodeUnderTest m -> [LeiosTestBlock] -> m ()
addBlocks NodeUnderTest (IOSim s)
node [LeiosTestBlock]
forgottenChain
(,,,) Bool
forgotten Int
certifiedAtStart
(Point LeiosTestBlock
-> [Relayed] -> (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> IOSim s (Point LeiosTestBlock)
-> IOSim
s ([Relayed] -> (Bool, Int, Point LeiosTestBlock, [Relayed]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
forall s.
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
awaitTip NodeUnderTest (IOSim s)
node ([LeiosTestBlock] -> Point LeiosTestBlock
lastPoint [LeiosTestBlock]
forgottenChain)
IOSim s ([Relayed] -> (Bool, Int, Point LeiosTestBlock, [Relayed]))
-> IOSim s [Relayed]
-> IOSim s (Bool, Int, Point LeiosTestBlock, [Relayed])
forall a b. IOSim s (a -> b) -> IOSim s a -> IOSim s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Listener s -> Int -> IOSim s [Relayed]
forall s. Listener s -> Int -> IOSim s [Relayed]
relayedBy Listener s
heardByRival Int
1
pure (beforeRestart, afterRestart)
where
certifiedCount :: NodeUnderTest f -> f Int
certifiedCount NodeUnderTest f
node =
Map LeiosClaim LeiosAnnouncement -> Int
forall k a. Map k a -> Int
Map.size (Map LeiosClaim LeiosAnnouncement -> Int)
-> f (Map LeiosClaim LeiosAnnouncement) -> f Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM f (Map LeiosClaim LeiosAnnouncement)
-> f (Map LeiosClaim LeiosAnnouncement)
forall a. HasCallStack => STM f a -> f a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (NodeUnderTest f -> STM f (Map LeiosClaim LeiosAnnouncement)
forall (m :: * -> *).
NodeUnderTest m -> STM m (Map LeiosClaim LeiosAnnouncement)
nodeNewLeiosValidClaims NodeUnderTest f
node)
holds :: NodeUnderTest m -> LeiosTestBlock -> m Bool
holds NodeUnderTest m
node LeiosTestBlock
blk = STM m Bool -> m Bool
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m Bool -> m Bool) -> STM m Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ ((Point LeiosTestBlock -> Bool) -> Point LeiosTestBlock -> Bool
forall a b. (a -> b) -> a -> b
$ LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint LeiosTestBlock
blk) ((Point LeiosTestBlock -> Bool) -> Bool)
-> STM m (Point LeiosTestBlock -> Bool) -> STM m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ChainDB m LeiosTestBlock -> STM m (Point LeiosTestBlock -> Bool)
forall (m :: * -> *) blk.
ChainDB m blk -> STM m (Point blk -> Bool)
ChainDB.getIsFetched (NodeUnderTest m -> ChainDB m LeiosTestBlock
forall (m :: * -> *). NodeUnderTest m -> ChainDB m LeiosTestBlock
nodeChainDB NodeUnderTest m
node)
nodeAnnouncesToLateListener :: IOSim s [Relayed]
nodeAnnouncesToLateListener :: forall s. IOSim s [Relayed]
nodeAnnouncesToLateListener = (NodeUnderTest (IOSim s) -> IOSim s [Relayed]) -> IOSim s [Relayed]
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed])
-> (NodeUnderTest (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
heardByHolder <- NodeUnderTest (IOSim s) -> IOSim s (Listener s)
forall s. NodeUnderTest (IOSim s) -> IOSim s (Listener s)
newListener NodeUnderTest (IOSim s)
node
heardByListener <- newListener node
notifications <- newTQueueIO
atomically $
writeTQueue notifications (MsgLeiosBlockAnnouncement (ltbHeader announcingFetched))
let holder =
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Listener s
-> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Listener s
-> EnvPeer (IOSim s)
holdingFetchedListening NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications Listener s
heardByHolder
listener =
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
listening NodeUnderTest (IOSim s)
node Listener s
heardByListener
withNodeVsEnvConnection node (PeerAddr 1) holder $ \NodeVsEnvConnection (IOSim s)
_holderConn -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) [Relayed] -> STM (IOSim s) [Relayed]
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar (Listener s -> StrictTVar (IOSim s) [Relayed]
forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed Listener s
heardByHolder) STM (IOSim s) [Relayed]
-> ([Relayed] -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
Bool -> STM s ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM s ()) -> ([Relayed] -> Bool) -> [Relayed] -> STM s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Bool
not (Bool -> Bool) -> ([Relayed] -> Bool) -> [Relayed] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Relayed] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) EnvPeer (IOSim s)
listener ((NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed])
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_listenerConn -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ())
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
-> STM (IOSim s) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
(StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTQueue m a -> a -> STM m ()
writeTQueue StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications)
[ LeiosPoint
-> Word32
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Word32
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockOffer LeiosPoint
fetchedPoint (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb)
, LeiosPoint
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockTxsOffer LeiosPoint
fetchedPoint
]
Listener s -> Int -> IOSim s [Relayed]
forall s. Listener s -> Int -> IOSim s [Relayed]
relayedBy Listener s
heardByListener Int
3
nodeDisconnectsReofferAfterRequest :: IOSim s (Maybe String)
nodeDisconnectsReofferAfterRequest :: forall s. IOSim s (Maybe [Char])
nodeDisconnectsReofferAfterRequest = (NodeUnderTest (IOSim s) -> IOSim s (Maybe [Char]))
-> IOSim s (Maybe [Char])
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s (Maybe [Char]))
-> IOSim s (Maybe [Char]))
-> (NodeUnderTest (IOSim s) -> IOSim s (Maybe [Char]))
-> IOSim s (Maybe [Char])
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
requested <- Bool -> IOSim s (StrictTVar (IOSim s) Bool)
forall (m :: * -> *) a. MonadSTM m => a -> m (StrictTVar m a)
newTVarIO Bool
False
notifications <- newTQueueIO
let offer ::
Message (LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote) LN.StBusy LN.StIdle
offer = LeiosPoint
-> Word32
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Word32
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockOffer LeiosPoint
fetchedPoint (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb)
envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> StrictTVar (IOSim s) Bool
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTVar (IOSim s) Bool
-> Channel (IOSim s) ByteString
-> IOSim s ()
withholding NodeUnderTest (IOSim s)
node StrictTVar (IOSim s) Bool
requested
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
atomically $
mapM_ (writeTQueue notifications) [MsgLeiosBlockAnnouncement (ltbHeader announcingFetched), offer]
withNodeVsEnvConnection node (PeerAddr 1) envPeer $ \NodeVsEnvConnection (IOSim s)
conn -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) Bool -> STM (IOSim s) Bool
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar (IOSim s) Bool
requested STM (IOSim s) Bool
-> (Bool -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTQueue m a -> a -> STM m ()
writeTQueue StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
offer
client <-
IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
-> (STM s (Either SomeException NodeToNodeInitiatorResult)
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (IOError
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall e a. Exception e => e -> IOSim s a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO (IOError
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> IOError
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a b. (a -> b) -> a -> b
$ [Char] -> IOError
userError [Char]
"the node does not run a LeiosNotify client") STM s (Either SomeException NodeToNodeInitiatorResult)
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim
s (STM s (Either SomeException NodeToNodeInitiatorResult)))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
-> IOSim s (STM s (Either SomeException NodeToNodeInitiatorResult))
forall a b. (a -> b) -> a -> b
$
MiniProtocolNum
-> Map
MiniProtocolNum
(STM s (Either SomeException NodeToNodeInitiatorResult))
-> Maybe (STM s (Either SomeException NodeToNodeInitiatorResult))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup MiniProtocolNum
leiosNotifyMiniProtocolNum (NodeVsEnvConnection (IOSim s)
-> Map
MiniProtocolNum
(STM (IOSim s) (Either SomeException NodeToNodeInitiatorResult))
forall (m :: * -> *).
NodeVsEnvConnection m
-> Map
MiniProtocolNum
(STM m (Either SomeException NodeToNodeInitiatorResult))
connNodeInitiators NodeVsEnvConnection (IOSim s)
conn)
atomically client <&> \case
Left SomeException
e -> [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just (SomeException -> [Char]
forall a. Show a => a -> [Char]
show SomeException
e)
Right NodeToNodeInitiatorResult
_ -> Maybe [Char]
forall a. Maybe a
Nothing
withholding ::
NodeUnderTest (IOSim s) ->
StrictTVar (IOSim s) Bool ->
Channel (IOSim s) ByteString ->
IOSim s ()
withholding :: forall s.
NodeUnderTest (IOSim s)
-> StrictTVar (IOSim s) Bool
-> Channel (IOSim s) ByteString
-> IOSim s ()
withholding NodeUnderTest (IOSim s)
node StrictTVar (IOSim s) Bool
requested Channel (IOSim s) ByteString
chan =
((), Maybe ByteString) -> ()
forall a b. (a, b) -> a
fst
(((), Maybe ByteString) -> ())
-> IOSim s ((), Maybe ByteString) -> IOSim s ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
-> Channel (IOSim s) ByteString
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsServer
'NonPipelined
'StIdle
(IOSim s)
()
-> IOSim s ((), Maybe ByteString)
forall ps (st :: ps) (pr :: PeerRole) failure bytes (m :: * -> *)
a.
(MonadEvaluate m, MonadThrow m, ShowProxy ps,
forall (st' :: ps) stok. (stok ~ StateToken st') => Show stok,
NFData a, NFData failure, Show failure) =>
Tracer m (TraceSendRecv ps)
-> Codec ps failure m bytes
-> Channel m bytes
-> Peer ps pr 'NonPipelined st m a
-> m (a, Maybe bytes)
runPeer Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall (m :: * -> *) a. Monad m => Tracer m a
nullTracer (NodeUnderTest (IOSim s)
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
forall s. NodeUnderTest (IOSim s) -> LeiosFetchCodec s
envLeiosFetchCodec NodeUnderTest (IOSim s)
node) Channel (IOSim s) ByteString
chan (LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsServer
'NonPipelined
'StIdle
(IOSim s)
()
forall point eb tx (m :: * -> *).
Functor m =>
LeiosFetchRequestHandler point eb tx m
-> LeiosFetchServerPeer point eb tx m ()
leiosFetchServerPeer LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s)
withhold)
where
withhold :: LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s)
withhold = (forall (st :: LeiosFetchBusy
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy st)
-> IOSim
s
(Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle))
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s)
forall point eb tx (m :: * -> *).
(forall (st :: LeiosFetchBusy point eb tx).
Message (LeiosFetch point eb tx) 'StIdle ('StBusy st)
-> m (Message (LeiosFetch point eb tx) ('StBusy st) 'StIdle))
-> LeiosFetchRequestHandler point eb tx m
MkLeiosFetchRequestHandler ((forall (st :: LeiosFetchBusy
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy st)
-> IOSim
s
(Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle))
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s))
-> (forall (st :: LeiosFetchBusy
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy st)
-> IOSim
s
(Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle))
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s)
forall a b. (a -> b) -> a -> b
$ \Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy st)
_request -> do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) Bool -> Bool -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar (IOSim s) Bool
requested Bool
True
STM
(IOSim s)
(Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle)
-> IOSim
s
(Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle)
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM
(IOSim s)
(Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle)
forall a. STM (IOSim s) a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
data LieArrival = TxBeforeBody | BodyBeforeTx
deriving (Int -> LieArrival -> [Char] -> [Char]
[LieArrival] -> [Char] -> [Char]
LieArrival -> [Char]
(Int -> LieArrival -> [Char] -> [Char])
-> (LieArrival -> [Char])
-> ([LieArrival] -> [Char] -> [Char])
-> Show LieArrival
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> LieArrival -> [Char] -> [Char]
showsPrec :: Int -> LieArrival -> [Char] -> [Char]
$cshow :: LieArrival -> [Char]
show :: LieArrival -> [Char]
$cshowList :: [LieArrival] -> [Char] -> [Char]
showList :: [LieArrival] -> [Char] -> [Char]
Show, Int -> LieArrival
LieArrival -> Int
LieArrival -> [LieArrival]
LieArrival -> LieArrival
LieArrival -> LieArrival -> [LieArrival]
LieArrival -> LieArrival -> LieArrival -> [LieArrival]
(LieArrival -> LieArrival)
-> (LieArrival -> LieArrival)
-> (Int -> LieArrival)
-> (LieArrival -> Int)
-> (LieArrival -> [LieArrival])
-> (LieArrival -> LieArrival -> [LieArrival])
-> (LieArrival -> LieArrival -> [LieArrival])
-> (LieArrival -> LieArrival -> LieArrival -> [LieArrival])
-> Enum LieArrival
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: LieArrival -> LieArrival
succ :: LieArrival -> LieArrival
$cpred :: LieArrival -> LieArrival
pred :: LieArrival -> LieArrival
$ctoEnum :: Int -> LieArrival
toEnum :: Int -> LieArrival
$cfromEnum :: LieArrival -> Int
fromEnum :: LieArrival -> Int
$cenumFrom :: LieArrival -> [LieArrival]
enumFrom :: LieArrival -> [LieArrival]
$cenumFromThen :: LieArrival -> LieArrival -> [LieArrival]
enumFromThen :: LieArrival -> LieArrival -> [LieArrival]
$cenumFromTo :: LieArrival -> LieArrival -> [LieArrival]
enumFromTo :: LieArrival -> LieArrival -> [LieArrival]
$cenumFromThenTo :: LieArrival -> LieArrival -> LieArrival -> [LieArrival]
enumFromThenTo :: LieArrival -> LieArrival -> LieArrival -> [LieArrival]
Enum, LieArrival
LieArrival -> LieArrival -> Bounded LieArrival
forall a. a -> a -> Bounded a
$cminBound :: LieArrival
minBound :: LieArrival
$cmaxBound :: LieArrival
maxBound :: LieArrival
Bounded)
sharedTx :: LeiosTx
sharedTx :: LeiosTx
sharedTx = ByteString -> LeiosTx
MkLeiosTx (Int -> Word8 -> ByteString
BS.replicate Int
50 Word8
4)
honestEb :: EndorserBlock
honestEb :: EndorserBlock
honestEb = [(TxHash, Word32)] -> EndorserBlock
mkEndorserBlock [(LeiosTx -> TxHash
hashLeiosTx LeiosTx
sharedTx, Word32
50)]
lyingEb :: EndorserBlock
lyingEb :: EndorserBlock
lyingEb = [(TxHash, Word32)] -> EndorserBlock
mkEndorserBlock [(LeiosTx -> TxHash
hashLeiosTx LeiosTx
sharedTx, Word32
1)]
relayedHonestEb :: [Relayed]
relayedHonestEb :: [Relayed]
relayedHonestEb =
[ Relayed
RelayedAnnouncement
, LeiosPoint -> Word32 -> Relayed
RelayedBlockOffer LeiosPoint
honestPoint (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
honestEb)
, LeiosPoint -> Relayed
RelayedBlockTxsOffer LeiosPoint
honestPoint
]
where
honestPoint :: LeiosPoint
honestPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingHonest) (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
honestEb)
relayedLyingEb :: [Relayed]
relayedLyingEb :: [Relayed]
relayedLyingEb =
[Relayed
RelayedAnnouncement, LeiosPoint -> Word32 -> Relayed
RelayedBlockOffer LeiosPoint
lyingPoint (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
lyingEb)]
lyingPoint :: LeiosPoint
lyingPoint :: LeiosPoint
lyingPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingLying) (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
lyingEb)
announcingHonest, announcingLying :: LeiosTestBlock
announcingHonest :: LeiosTestBlock
announcingHonest =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement
(EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
honestEb)
(EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
honestEb)
(LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock (Word64 -> LeiosTestBlock
firstLeiosBlock Word64
4))
announcingLying :: LeiosTestBlock
announcingLying =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement
(EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
lyingEb)
(EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
lyingEb)
((LeiosTestBlock -> LeiosTestBlock)
-> LeiosTestBlock -> [LeiosTestBlock]
forall a. (a -> a) -> a -> [a]
iterate LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock (Word64 -> LeiosTestBlock
firstLeiosBlock Word64
5) [LeiosTestBlock] -> Int -> LeiosTestBlock
forall a. HasCallStack => [a] -> Int -> a
!! Int
3)
nodeOffersLyingEb :: LieArrival -> IOSim s [Relayed]
nodeOffersLyingEb :: forall s. LieArrival -> IOSim s [Relayed]
nodeOffersLyingEb LieArrival
arrival = (NodeUnderTest (IOSim s) -> IOSim s [Relayed]) -> IOSim s [Relayed]
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed])
-> (NodeUnderTest (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
next <- LeiosAcquisitions (IOSim s)
-> IOSim s (STM (IOSim s) LeiosAcquisition)
forall (m :: * -> *).
LeiosAcquisitions m -> m (STM m LeiosAcquisition)
subscribeLeiosAcquisitions (NodeUnderTest (IOSim s) -> LeiosAcquisitions (IOSim s)
forall (m :: * -> *). NodeUnderTest m -> LeiosAcquisitions m
nodeLeiosAcquisitions NodeUnderTest (IOSim s)
node)
heard <- newListener node
holderNotifications <- newTQueueIO
liarNotifications <- newTQueueIO
let listener =
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
listening NodeUnderTest (IOSim s)
node Listener s
heard
holder =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
holderNotifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
serving EndorserBlock
honestEb (LeiosTx -> Vector LeiosTx
forall a. a -> Vector a
V.singleton LeiosTx
sharedTx) NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
liar =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
liarNotifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
serving EndorserBlock
lyingEb Vector LeiosTx
forall a. Vector a
V.empty NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
servesTheTx = do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ())
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
-> STM (IOSim s) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTQueue m a -> a -> STM m ()
writeTQueue StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
holderNotifications) (EndorserBlock
-> LeiosTestBlock
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
announcingAndOffering EndorserBlock
honestEb LeiosTestBlock
announcingHonest)
STM (IOSim s) LeiosAcquisition -> Acquired -> IOSim s ()
forall s. STM (IOSim s) LeiosAcquisition -> Acquired -> IOSim s ()
awaitAcquired STM (IOSim s) LeiosAcquisition
STM s LeiosAcquisition
next (Acquired -> IOSim s ()) -> Acquired -> IOSim s ()
forall a b. (a -> b) -> a -> b
$
LeiosPoint -> Acquired
AcquiredClosure (SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingHonest) (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
honestEb))
servesTheLie = do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ())
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
-> STM (IOSim s) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
(StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTQueue m a -> a -> STM m ()
writeTQueue StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
liarNotifications)
[ Header LeiosTestBlock
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall announcement point vote.
announcement
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockAnnouncement (LeiosTestBlock -> Header LeiosTestBlock
ltbHeader LeiosTestBlock
announcingLying)
, LeiosPoint
-> Word32
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Word32
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockOffer LeiosPoint
lyingPoint (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
lyingEb)
]
STM (IOSim s) LeiosAcquisition -> Acquired -> IOSim s ()
forall s. STM (IOSim s) LeiosAcquisition -> Acquired -> IOSim s ()
awaitAcquired STM (IOSim s) LeiosAcquisition
STM s LeiosAcquisition
next (LeiosPoint -> Acquired
AcquiredBody LeiosPoint
lyingPoint)
threadDelay 6
withNodeVsEnvConnection node (PeerAddr 1) listener $ \NodeVsEnvConnection (IOSim s)
_listenerConn ->
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) EnvPeer (IOSim s)
holder ((NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed])
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_holderConn ->
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
3) EnvPeer (IOSim s)
liar ((NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed])
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_liarConn -> do
case LieArrival
arrival of
LieArrival
TxBeforeBody -> IOSim s ()
servesTheTx IOSim s () -> IOSim s () -> IOSim s ()
forall a b. IOSim s a -> IOSim s b -> IOSim s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IOSim s ()
servesTheLie
LieArrival
BodyBeforeTx -> IOSim s ()
servesTheLie IOSim s () -> IOSim s () -> IOSim s ()
forall a b. IOSim s a -> IOSim s b -> IOSim s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IOSim s ()
servesTheTx
Listener s -> Int -> IOSim s [Relayed]
forall s. Listener s -> Int -> IOSim s [Relayed]
relayedBy Listener s
heard Int
5
relayedBy :: Listener s -> Int -> IOSim s [Relayed]
relayedBy :: forall s. Listener s -> Int -> IOSim s [Relayed]
relayedBy Listener s
listener Int
n = do
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) [Relayed] -> STM (IOSim s) [Relayed]
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar (Listener s -> StrictTVar (IOSim s) [Relayed]
forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed Listener s
listener) STM (IOSim s) [Relayed]
-> ([Relayed] -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
Bool -> STM s ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM s ()) -> ([Relayed] -> Bool) -> [Relayed] -> STM s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
n) (Int -> Bool) -> ([Relayed] -> Int) -> [Relayed] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Relayed] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
DiffTime -> IOSim s ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay DiffTime
relayHorizon
STM (IOSim s) [Relayed] -> IOSim s [Relayed]
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) [Relayed] -> IOSim s [Relayed])
-> STM (IOSim s) [Relayed] -> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ do
relays <- StrictTVar (IOSim s) [Relayed] -> STM (IOSim s) [Relayed]
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar (Listener s -> StrictTVar (IOSim s) [Relayed]
forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed Listener s
listener)
unfetched <- readTVar (lsUnfetched listener)
pure $ relays <> [RelayedDishonestly ("not served: " <> show offer) | offer <- unfetched]
relayHorizon :: DiffTime
relayHorizon :: DiffTime
relayHorizon = DiffTime
5
awaitAcquired :: STM (IOSim s) LeiosAcquisition -> Acquired -> IOSim s ()
awaitAcquired :: forall s. STM (IOSim s) LeiosAcquisition -> Acquired -> IOSim s ()
awaitAcquired STM (IOSim s) LeiosAcquisition
next Acquired
acquired = do
got <- LeiosAcquisition -> Acquired
acquiredOf (LeiosAcquisition -> Acquired)
-> IOSim s LeiosAcquisition -> IOSim s Acquired
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM (IOSim s) LeiosAcquisition -> IOSim s LeiosAcquisition
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) LeiosAcquisition
next
unless (got == acquired) $ awaitAcquired next acquired
announcingAndOffering ::
EndorserBlock ->
LeiosTestBlock ->
[Message (LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote) LN.StBusy LN.StIdle]
announcingAndOffering :: EndorserBlock
-> LeiosTestBlock
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
announcingAndOffering EndorserBlock
eb LeiosTestBlock
blk =
[ Header LeiosTestBlock
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall announcement point vote.
announcement
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockAnnouncement (LeiosTestBlock -> Header LeiosTestBlock
ltbHeader LeiosTestBlock
blk)
, LeiosPoint
-> Word32
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Word32
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockOffer LeiosPoint
point (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
eb)
, LeiosPoint
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
forall point announcement vote.
point
-> Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
MsgLeiosBlockTxsOffer LeiosPoint
point
]
where
point :: LeiosPoint
point = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
blk) (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
eb)
readOutstanding ::
NodeUnderTest (IOSim s) -> IOSim s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
readOutstanding :: forall s.
NodeUnderTest (IOSim s)
-> IOSim
s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
readOutstanding NodeUnderTest (IOSim s)
node = StrictMVar
(IOSim s)
(LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
-> IOSim
s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
forall (m :: * -> *) a. MonadMVar m => StrictMVar m a -> m a
IOLike.readMVar (LeiosFetchClientContext
(IOSim s) (LeiosPeerLifetimeId (ConnectionId PeerAddr))
-> StrictMVar
(IOSim s)
(LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
forall (m :: * -> *) peer.
LeiosFetchClientContext m peer
-> StrictMVar m (LeiosOutstanding peer)
lfcOutstanding (LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
-> LeiosFetchClientContext
(IOSim s) (LeiosPeerLifetimeId (ConnectionId PeerAddr))
forall (m :: * -> *) peer blk.
LeiosFetchKernel m peer blk
-> LeiosFetchClientContext m (LeiosPeerLifetimeId peer)
lfkContext (NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
-> LeiosFetchKernel
(IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk
-> LeiosFetchKernel m (ConnectionId addrNTN) blk
getLeiosFetchKernel (NodeUnderTest (IOSim s)
-> NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
forall (m :: * -> *).
NodeUnderTest m
-> NodeKernel m PeerAddr (ConnectionId ()) LeiosTestBlock
nodeKernel NodeUnderTest (IOSim s)
node))))
awaitPrunedPast :: NodeUnderTest (IOSim s) -> SlotNo -> IOSim s ()
awaitPrunedPast :: forall s. NodeUnderTest (IOSim s) -> SlotNo -> IOSim s ()
awaitPrunedPast NodeUnderTest (IOSim s)
node SlotNo
slot = do
outstanding <- NodeUnderTest (IOSim s)
-> IOSim
s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
forall s.
NodeUnderTest (IOSim s)
-> IOSim
s (LeiosOutstanding (LeiosPeerLifetimeId (ConnectionId PeerAddr)))
readOutstanding NodeUnderTest (IOSim s)
node
if outstandingPrunedSlot outstanding > slot
then
threadDelay 1
else threadDelay 0.1 >> awaitPrunedPast node slot
awaitTip :: NodeUnderTest (IOSim s) -> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
awaitTip :: forall s.
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> IOSim s (Point LeiosTestBlock)
awaitTip NodeUnderTest (IOSim s)
node Point LeiosTestBlock
point = do
_ <- DiffTime -> IOSim s () -> IOSim s (Maybe ())
forall a. DiffTime -> IOSim s a -> IOSim s (Maybe a)
forall (m :: * -> *) a.
MonadTimer m =>
DiffTime -> m a -> m (Maybe a)
timeout DiffTime
10 (IOSim s () -> IOSim s (Maybe ()))
-> IOSim s () -> IOSim s (Maybe ())
forall a b. (a -> b) -> a -> b
$ STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ ChainDB (IOSim s) LeiosTestBlock
-> STM (IOSim s) (Point LeiosTestBlock)
forall (m :: * -> *) blk. ChainDB m blk -> STM m (Point blk)
ChainDB.getTipPoint (NodeUnderTest (IOSim s) -> ChainDB (IOSim s) LeiosTestBlock
forall (m :: * -> *). NodeUnderTest m -> ChainDB m LeiosTestBlock
nodeChainDB NodeUnderTest (IOSim s)
node) STM (IOSim s) (Point LeiosTestBlock)
-> (Point LeiosTestBlock -> STM (IOSim s) ()) -> STM (IOSim s) ()
forall a b.
STM (IOSim s) a -> (a -> STM (IOSim s) b) -> STM (IOSim s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM (IOSim s) ()
Bool -> STM s ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM s ())
-> (Point LeiosTestBlock -> Bool)
-> Point LeiosTestBlock
-> STM s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Point LeiosTestBlock -> Point LeiosTestBlock -> Bool
forall a. Eq a => a -> a -> Bool
== Point LeiosTestBlock
point)
atomically $ ChainDB.getTipPoint (nodeChainDB node)
lastPoint :: [LeiosTestBlock] -> Point LeiosTestBlock
lastPoint :: [LeiosTestBlock] -> Point LeiosTestBlock
lastPoint = Point LeiosTestBlock
-> (LeiosTestBlock -> Point LeiosTestBlock)
-> Maybe LeiosTestBlock
-> Point LeiosTestBlock
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Point LeiosTestBlock
forall {k} (block :: k). Point block
GenesisPoint LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint (Maybe LeiosTestBlock -> Point LeiosTestBlock)
-> ([LeiosTestBlock] -> Maybe LeiosTestBlock)
-> [LeiosTestBlock]
-> Point LeiosTestBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LeiosTestBlock] -> Maybe LeiosTestBlock
forall a. [a] -> Maybe a
listToMaybe ([LeiosTestBlock] -> Maybe LeiosTestBlock)
-> ([LeiosTestBlock] -> [LeiosTestBlock])
-> [LeiosTestBlock]
-> Maybe LeiosTestBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LeiosTestBlock] -> [LeiosTestBlock]
forall a. [a] -> [a]
reverse
acquiredOf :: LeiosAcquisition -> Acquired
acquiredOf :: LeiosAcquisition -> Acquired
acquiredOf = \case
AcquiredEb LeiosPoint
point Word32
_bodySize -> LeiosPoint -> Acquired
AcquiredBody LeiosPoint
point
AcquiredEbTxs LeiosPoint
point -> LeiosPoint -> Acquired
AcquiredClosure LeiosPoint
point
data Listener s = Listener
{ forall s. Listener s -> StrictTVar (IOSim s) [Relayed]
lsRelayed :: StrictTVar (IOSim s) [Relayed]
, forall s. Listener s -> StrictTVar (IOSim s) [FetchBack]
lsUnfetched :: StrictTVar (IOSim s) [FetchBack]
, forall s. Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
lsNotifyClient :: Channel (IOSim s) ByteString -> IOSim s ()
, forall s. Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
lsFetchClient :: Channel (IOSim s) ByteString -> IOSim s ()
}
data FetchBack = FetchBackBody LeiosPoint BytesSize | FetchBackClosure LeiosPoint
deriving (FetchBack -> FetchBack -> Bool
(FetchBack -> FetchBack -> Bool)
-> (FetchBack -> FetchBack -> Bool) -> Eq FetchBack
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FetchBack -> FetchBack -> Bool
== :: FetchBack -> FetchBack -> Bool
$c/= :: FetchBack -> FetchBack -> Bool
/= :: FetchBack -> FetchBack -> Bool
Eq, Int -> FetchBack -> [Char] -> [Char]
[FetchBack] -> [Char] -> [Char]
FetchBack -> [Char]
(Int -> FetchBack -> [Char] -> [Char])
-> (FetchBack -> [Char])
-> ([FetchBack] -> [Char] -> [Char])
-> Show FetchBack
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> FetchBack -> [Char] -> [Char]
showsPrec :: Int -> FetchBack -> [Char] -> [Char]
$cshow :: FetchBack -> [Char]
show :: FetchBack -> [Char]
$cshowList :: [FetchBack] -> [Char] -> [Char]
showList :: [FetchBack] -> [Char] -> [Char]
Show)
newListener :: NodeUnderTest (IOSim s) -> IOSim s (Listener s)
newListener :: forall s. NodeUnderTest (IOSim s) -> IOSim s (Listener s)
newListener NodeUnderTest (IOSim s)
node = NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> NominalDiffTime -> IOSim s (Listener s)
forall s.
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> NominalDiffTime -> IOSim s (Listener s)
newListenerWith NodeUnderTest (IOSim s)
node Point LeiosTestBlock
forall {k} (block :: k). Point block
GenesisPoint NominalDiffTime
0
newListenerWith ::
NodeUnderTest (IOSim s) -> Point LeiosTestBlock -> NominalDiffTime -> IOSim s (Listener s)
newListenerWith :: forall s.
NodeUnderTest (IOSim s)
-> Point LeiosTestBlock -> NominalDiffTime -> IOSim s (Listener s)
newListenerWith NodeUnderTest (IOSim s)
node Point LeiosTestBlock
immTip NominalDiffTime
offset = do
relayed <- [Relayed] -> IOSim s (StrictTVar (IOSim s) [Relayed])
forall (m :: * -> *) a. MonadSTM m => a -> m (StrictTVar m a)
newTVarIO []
unfetched <- newTVarIO []
toFetch <- newTQueueIO
stVar <- newTVarIO emptyLeiosNotifyPeerState
announceState <- newAnnounceState defaultLeiosAnnouncementAgeLimits =<< NotifyLog.newNotifyLog
let record Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
msg = do
st <- SlotNo
-> LeiosNotifyPeerState LeiosTestBlock
-> LeiosNotifyPeerState LeiosTestBlock
forall blk.
(ConvertRawHash blk, GetHeader blk) =>
SlotNo -> LeiosNotifyPeerState blk -> LeiosNotifyPeerState blk
pruneLeiosNotifyPeerState (SlotNo -> (SlotNo -> SlotNo) -> WithOrigin SlotNo -> SlotNo
forall b t. b -> (t -> b) -> WithOrigin t -> b
withOrigin SlotNo
0 SlotNo -> SlotNo
forall a. a -> a
id (Point LeiosTestBlock -> WithOrigin SlotNo
forall {k} (block :: k). Point block -> WithOrigin SlotNo
pointSlot Point LeiosTestBlock
immTip)) (LeiosNotifyPeerState LeiosTestBlock
-> LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (LeiosNotifyPeerState LeiosTestBlock)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictTVar (IOSim s) (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (LeiosNotifyPeerState LeiosTestBlock)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> m a
readTVarIO StrictTVar (IOSim s) (LeiosNotifyPeerState LeiosTestBlock)
stVar
checked <- case msg of
MsgLeiosBlockAnnouncement Header LeiosTestBlock
hdr ->
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> m (Either e a)
try @_ @InFutureCheck.HeaderArrivalException
( ExceptT
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(IOSim s)
(LeiosNotifyPeerState LeiosTestBlock)
-> IOSim
s
(Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(IOSim s)
(LeiosNotifyPeerState LeiosTestBlock)
-> IOSim
s
(Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock)))
-> ExceptT
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(IOSim s)
(LeiosNotifyPeerState LeiosTestBlock)
-> IOSim
s
(Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock))
forall a b. (a -> b) -> a -> b
$
SystemTime (IOSim s)
-> SomeHeaderInFutureCheck (IOSim s) LeiosTestBlock
-> TopLevelConfig LeiosTestBlock
-> AnnounceState (IOSim s) LeiosTestBlock
-> (ValidAnnouncement LeiosTestBlock -> STM (IOSim s) ())
-> ExtLedgerState LeiosTestBlock EmptyMK
-> LeiosNotifyPeerState LeiosTestBlock
-> Header LeiosTestBlock
-> ExceptT
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(IOSim s)
(LeiosNotifyPeerState LeiosTestBlock)
forall (m :: * -> *) blk.
(IOLike m, LedgerSupportsProtocol blk, ConvertRawHash blk) =>
SystemTime m
-> SomeHeaderInFutureCheck m blk
-> TopLevelConfig blk
-> AnnounceState m blk
-> (ValidAnnouncement blk -> STM m ())
-> ExtLedgerState blk EmptyMK
-> LeiosNotifyPeerState blk
-> Header blk
-> ExceptT
(ExnLeiosNotifyInvalidAnnouncement blk)
m
(LeiosNotifyPeerState blk)
onLeiosNotifyAnnouncement
SystemTime (IOSim s)
systemTime
(ClockSkew
-> SystemTime (IOSim s)
-> SomeHeaderInFutureCheck (IOSim s) LeiosTestBlock
forall blk (m :: * -> *).
(HasHeader blk, HasHeader (Header blk), HasHardForkHistory blk,
MonadDelay m) =>
ClockSkew -> SystemTime m -> SomeHeaderInFutureCheck m blk
InFutureCheck.realHeaderInFutureCheck ClockSkew
InFutureCheck.defaultClockSkew SystemTime (IOSim s)
systemTime)
TopLevelConfig LeiosTestBlock
cfg
AnnounceState (IOSim s) LeiosTestBlock
announceState
(\ValidAnnouncement LeiosTestBlock
_valid -> () -> STM s ()
forall a. a -> STM s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
ExtLedgerState LeiosTestBlock EmptyMK
immLedger
LeiosNotifyPeerState LeiosTestBlock
st
Header LeiosTestBlock
hdr
)
IOSim
s
(Either
HeaderArrivalException
(Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock)))
-> (Either
HeaderArrivalException
(Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock))
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (HeaderArrivalException
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
-> (Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
-> Either
HeaderArrivalException
(Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock))
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ([Char] -> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a b. a -> Either a b
Left ([Char] -> Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
-> (HeaderArrivalException -> [Char])
-> HeaderArrivalException
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HeaderArrivalException -> [Char]
forall a. Show a => a -> [Char]
show) ((ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock -> [Char])
-> Either
(ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock)
(LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ExnLeiosNotifyInvalidAnnouncement LeiosTestBlock -> [Char]
forall a. Show a => a -> [Char]
show)
MsgLeiosBlockOffer LeiosPoint
point Word32
size ->
Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock)))
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
forall a b. (a -> b) -> a -> b
$ (ExnLeiosNotifyInvalidOffer -> [Char])
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ExnLeiosNotifyInvalidOffer -> [Char]
forall a. Show a => a -> [Char]
show (Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
forall e a. Except e a -> Either e a
runExcept (Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock))
-> Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ TopLevelConfig LeiosTestBlock
-> ExtLedgerState LeiosTestBlock EmptyMK
-> LeiosPoint
-> Word32
-> LeiosNotifyPeerState LeiosTestBlock
-> Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
forall blk.
LedgerSupportsProtocol blk =>
TopLevelConfig blk
-> ExtLedgerState blk EmptyMK
-> LeiosPoint
-> Word32
-> LeiosNotifyPeerState blk
-> Except ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState blk)
checkLeiosBlockOffer TopLevelConfig LeiosTestBlock
cfg ExtLedgerState LeiosTestBlock EmptyMK
immLedger LeiosPoint
point Word32
size LeiosNotifyPeerState LeiosTestBlock
st
MsgLeiosBlockTxsOffer LeiosPoint
point ->
Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock)))
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
forall a b. (a -> b) -> a -> b
$ (ExnLeiosNotifyInvalidOffer -> [Char])
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first ExnLeiosNotifyInvalidOffer -> [Char]
forall a. Show a => a -> [Char]
show (Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
forall e a. Except e a -> Either e a
runExcept (Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock))
-> Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
-> Either
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
forall a b. (a -> b) -> a -> b
$ LeiosPoint
-> LeiosNotifyPeerState LeiosTestBlock
-> Except
ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState LeiosTestBlock)
forall blk.
LeiosPoint
-> LeiosNotifyPeerState blk
-> Except ExnLeiosNotifyInvalidOffer (LeiosNotifyPeerState blk)
checkLeiosClosureOffer LeiosPoint
point LeiosNotifyPeerState LeiosTestBlock
st
Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
_ -> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock)))
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
-> IOSim s (Either [Char] (LeiosNotifyPeerState LeiosTestBlock))
forall a b. (a -> b) -> a -> b
$ LeiosNotifyPeerState LeiosTestBlock
-> Either [Char] (LeiosNotifyPeerState LeiosTestBlock)
forall a b. b -> Either a b
Right LeiosNotifyPeerState LeiosTestBlock
st
atomically $ case checked of
Left [Char]
why -> StrictTVar (IOSim s) [Relayed]
-> ([Relayed] -> [Relayed]) -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar (IOSim s) [Relayed]
relayed ([Relayed] -> [Relayed] -> [Relayed]
forall a. Semigroup a => a -> a -> a
<> [[Char] -> Relayed
RelayedDishonestly [Char]
why])
Right LeiosNotifyPeerState LeiosTestBlock
st' -> do
StrictTVar (IOSim s) (LeiosNotifyPeerState LeiosTestBlock)
-> LeiosNotifyPeerState LeiosTestBlock -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> a -> STM m ()
writeTVar StrictTVar (IOSim s) (LeiosNotifyPeerState LeiosTestBlock)
stVar LeiosNotifyPeerState LeiosTestBlock
st'
StrictTVar (IOSim s) [Relayed]
-> ([Relayed] -> [Relayed]) -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar (IOSim s) [Relayed]
relayed ([Relayed] -> [Relayed] -> [Relayed]
forall a. Semigroup a => a -> a -> a
<> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> Relayed
relayedOf Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
msg])
case Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
msg of
MsgLeiosBlockOffer LeiosPoint
point Word32
size -> FetchBack -> STM s ()
fetchBack (LeiosPoint -> Word32 -> FetchBack
FetchBackBody LeiosPoint
point Word32
size)
MsgLeiosBlockTxsOffer LeiosPoint
point -> FetchBack -> STM s ()
fetchBack (LeiosPoint -> FetchBack
FetchBackClosure LeiosPoint
point)
Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
_ -> () -> STM s ()
forall a. a -> STM s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
fetchBack FetchBack
offer = do
StrictTVar (IOSim s) [FetchBack]
-> ([FetchBack] -> [FetchBack]) -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar (IOSim s) [FetchBack]
unfetched ([FetchBack] -> [FetchBack] -> [FetchBack]
forall a. Semigroup a => a -> a -> a
<> [FetchBack
offer])
StrictTQueue (IOSim s) FetchBack -> FetchBack -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTQueue m a -> a -> STM m ()
writeTQueue StrictTQueue (IOSim s) FetchBack
toFetch FetchBack
offer
settle FetchBack
offer [[Char]]
whys = STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ do
StrictTVar (IOSim s) [FetchBack]
-> ([FetchBack] -> [FetchBack]) -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar (IOSim s) [FetchBack]
unfetched (FetchBack -> [FetchBack] -> [FetchBack]
forall a. Eq a => a -> [a] -> [a]
List.delete FetchBack
offer)
StrictTVar (IOSim s) [Relayed]
-> ([Relayed] -> [Relayed]) -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar (IOSim s) [Relayed]
relayed ([Relayed] -> [Relayed] -> [Relayed]
forall a. Semigroup a => a -> a -> a
<> ([Char] -> Relayed) -> [[Char]] -> [Relayed]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> Relayed
RelayedDishonestly [[Char]]
whys)
pure
Listener
{ lsRelayed = relayed
, lsUnfetched = unfetched
, lsNotifyClient = \Channel (IOSim s) ByteString
chan ->
((), Maybe ByteString) -> ()
forall a b. (a, b) -> a
fst
(((), Maybe ByteString) -> ())
-> IOSim s ((), Maybe ByteString) -> IOSim s ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tracer
(IOSim s)
(TraceSendRecv
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote))
-> Codec
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
DeserialiseFailure
(IOSim s)
ByteString
-> ProtocolSizeLimits
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
ByteString
-> ProtocolTimeLimits
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
-> Channel (IOSim s) ByteString
-> PeerPipelined
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
'StIdle
(IOSim s)
()
-> IOSim s ((), Maybe ByteString)
forall ps (st :: ps) (pr :: PeerRole) failure bytes (m :: * -> *)
a.
(MonadAsync m, MonadEvaluate m, MonadFork m, MonadMask m,
MonadTimer m, MonadThrow (STM m), ShowProxy ps,
forall (st' :: ps) stok. (stok ~ StateToken st') => Show stok,
NFData a, NFData failure, Show failure) =>
Tracer m (TraceSendRecv ps)
-> Codec ps failure m bytes
-> ProtocolSizeLimits ps bytes
-> ProtocolTimeLimits ps
-> Channel m bytes
-> PeerPipelined ps pr st m a
-> m (a, Maybe bytes)
runPipelinedPeerWithLimits
Tracer
(IOSim s)
(TraceSendRecv
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote))
forall (m :: * -> *) a. Monad m => Tracer m a
nullTracer
(NodeUnderTest (IOSim s)
-> Codec
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
DeserialiseFailure
(IOSim s)
ByteString
forall s. NodeUnderTest (IOSim s) -> LeiosNotifyCodec s
envLeiosNotifyCodec NodeUnderTest (IOSim s)
node)
((ByteString -> Word)
-> ProtocolSizeLimits
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
ByteString
forall bytes point announcement vote.
(bytes -> Word)
-> ProtocolSizeLimits (LeiosNotify point announcement vote) bytes
byteLimitsLeiosNotify (Int64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word) -> (ByteString -> Int64) -> ByteString -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
BSL.length))
ProtocolTimeLimits
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
forall point announcement vote.
ProtocolTimeLimits (LeiosNotify point announcement vote)
timeLimitsLeiosNotify
Channel (IOSim s) ByteString
chan
( Peer
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
('Pipelined 'Z C)
'StIdle
(IOSim s)
()
-> PeerPipelined
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
'StIdle
(IOSim s)
()
forall point announcement vote (m :: * -> *) a.
Peer
(LeiosNotify point announcement vote)
'AsClient
('Pipelined 'Z C)
'StIdle
m
a
-> LeiosNotifyClientPeerPipelined point announcement vote m a
toLeiosNotifyClientPeerPipelined (Peer
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
('Pipelined 'Z C)
'StIdle
(IOSim s)
()
-> PeerPipelined
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
'StIdle
(IOSim s)
())
-> Peer
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
('Pipelined 'Z C)
'StIdle
(IOSim s)
()
-> PeerPipelined
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$
STM (IOSim s) (Either () Int)
-> IOSim
s
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> IOSim s ())
-> Peer
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'AsClient
('Pipelined 'Z C)
'StIdle
(IOSim s)
()
forall (m :: * -> *) point announcement vote a.
(PrimMonad m, MonadSTM m) =>
STM m (Either a Int)
-> m (Message (LeiosNotify point announcement vote) 'StBusy 'StIdle
-> m ())
-> Peer
(LeiosNotify point announcement vote)
'AsClient
('Pipelined 'Z C)
'StIdle
m
a
leiosNotifyClientPeerPipelined (Either () Int -> STM s (Either () Int)
forall a. a -> STM s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> Either () Int
forall a b. b -> Either a b
Right Int
1)) ((Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> IOSim s ())
-> IOSim
s
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> IOSim s ())
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> IOSim s ()
record)
)
, lsFetchClient = \Channel (IOSim s) ByteString
chan ->
((), Maybe ByteString) -> ()
forall a b. (a, b) -> a
fst
(((), Maybe ByteString) -> ())
-> IOSim s ((), Maybe ByteString) -> IOSim s ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
-> Channel (IOSim s) ByteString
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
-> IOSim s ((), Maybe ByteString)
forall ps (st :: ps) (pr :: PeerRole) failure bytes (m :: * -> *)
a.
(MonadEvaluate m, MonadThrow m, ShowProxy ps,
forall (st' :: ps) stok. (stok ~ StateToken st') => Show stok,
NFData a, NFData failure, Show failure) =>
Tracer m (TraceSendRecv ps)
-> Codec ps failure m bytes
-> Channel m bytes
-> Peer ps pr 'NonPipelined st m a
-> m (a, Maybe bytes)
runPeer
Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall (m :: * -> *) a. Monad m => Tracer m a
nullTracer
(NodeUnderTest (IOSim s)
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
forall s. NodeUnderTest (IOSim s) -> LeiosFetchCodec s
envLeiosFetchCodec NodeUnderTest (IOSim s)
node)
Channel (IOSim s) ByteString
chan
(StrictTQueue (IOSim s) FetchBack
-> (FetchBack -> [[Char]] -> IOSim s ())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall s.
StrictTQueue (IOSim s) FetchBack
-> (FetchBack -> [[Char]] -> IOSim s ()) -> EnvClient s
fetchingBack StrictTQueue (IOSim s) FetchBack
toFetch FetchBack -> [[Char]] -> IOSim s ()
settle)
}
where
cfg :: TopLevelConfig LeiosTestBlock
cfg = NodeUnderTest (IOSim s) -> TopLevelConfig LeiosTestBlock
forall (m :: * -> *).
NodeUnderTest m -> TopLevelConfig LeiosTestBlock
nodeTopLevelConfig NodeUnderTest (IOSim s)
node
immLedger :: ExtLedgerState LeiosTestBlock EmptyMK
immLedger =
(ExtLedgerState LeiosTestBlock ValuesMK
-> ExtLedgerState LeiosTestBlock EmptyMK
forall (l :: StateKind) blk (mk :: * -> * -> *).
HasLedgerTables l blk =>
l blk mk -> l blk EmptyMK
forgetLedgerTables (LeiosTestLedgerConfig -> ExtLedgerState LeiosTestBlock ValuesMK
leiosTestInitExtLedger (TopLevelConfig LeiosTestBlock -> LedgerConfig LeiosTestBlock
forall blk. TopLevelConfig blk -> LedgerConfig blk
configLedger TopLevelConfig LeiosTestBlock
cfg)))
{ ledgerState = LeiosTestLedger immTip
}
systemTime :: SystemTime (IOSim s)
systemTime = SystemStart
-> Tracer (IOSim s) (TraceBlockchainTimeEvent UTCTime)
-> SystemTime (IOSim s)
forall (m :: * -> *).
(MonadTime m, MonadDelay m) =>
SystemStart
-> Tracer m (TraceBlockchainTimeEvent UTCTime) -> SystemTime m
defaultSystemTime (UTCTime -> SystemStart
SystemStart (NominalDiffTime -> UTCTime -> UTCTime
addUTCTime (NominalDiffTime -> NominalDiffTime
forall a. Num a => a -> a
negate NominalDiffTime
offset) UTCTime
start)) Tracer (IOSim s) (TraceBlockchainTimeEvent UTCTime)
forall (m :: * -> *) a. Monad m => Tracer m a
nullTracer
where
SystemStart UTCTime
start = BlockConfig LeiosTestBlock -> SystemStart
forall blk.
ConfigSupportsNode blk =>
BlockConfig blk -> SystemStart
getSystemStart (TopLevelConfig LeiosTestBlock -> BlockConfig LeiosTestBlock
forall blk. TopLevelConfig blk -> BlockConfig blk
configBlock TopLevelConfig LeiosTestBlock
cfg)
fetchingBack ::
StrictTQueue (IOSim s) FetchBack -> (FetchBack -> [String] -> IOSim s ()) -> EnvClient s
fetchingBack :: forall s.
StrictTQueue (IOSim s) FetchBack
-> (FetchBack -> [[Char]] -> IOSim s ()) -> EnvClient s
fetchingBack StrictTQueue (IOSim s) FetchBack
toFetch FetchBack -> [[Char]] -> IOSim s ()
settle = IOSim
s
(Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
m (Peer ps pr pl st m a) -> Peer ps pr pl st m a
Effect (IOSim
s
(Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> IOSim
s
(Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ do
offer <- STM (IOSim s) FetchBack -> IOSim s FetchBack
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) FetchBack -> IOSim s FetchBack)
-> STM (IOSim s) FetchBack -> IOSim s FetchBack
forall a b. (a -> b) -> a -> b
$ StrictTQueue (IOSim s) FetchBack -> STM (IOSim s) FetchBack
forall (m :: * -> *) a. MonadSTM m => StrictTQueue m a -> STM m a
readTQueue StrictTQueue (IOSim s) FetchBack
toFetch
pure $ case offer of
FetchBackBody LeiosPoint
point Word32
size ->
LeiosPoint
-> (EndorserBlock
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall s.
LeiosPoint -> (EndorserBlock -> EnvClient s) -> EnvClient s
requestingBody LeiosPoint
point ((EndorserBlock
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> (EndorserBlock
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ \EndorserBlock
eb ->
FetchBack
-> [[Char]]
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
settling FetchBack
offer ([[Char]]
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> [[Char]]
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$
[ [Char]
"served " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> (Hash HASH EraIndependentEbReferences, Word32) -> [Char]
forall a. Show a => a -> [Char]
show (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
eb, EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
eb)
| EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
eb Hash HASH EraIndependentEbReferences
-> Hash HASH EraIndependentEbReferences -> Bool
forall a. Eq a => a -> a -> Bool
/= LeiosPoint -> Hash HASH EraIndependentEbReferences
pointEbHash LeiosPoint
point Bool -> Bool -> Bool
|| EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
eb Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
size
]
FetchBackClosure LeiosPoint
point ->
LeiosPoint
-> (EndorserBlock
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall s.
LeiosPoint -> (EndorserBlock -> EnvClient s) -> EnvClient s
requestingBody LeiosPoint
point ((EndorserBlock
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> (EndorserBlock
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ \EndorserBlock
eb ->
let refs :: [(TxHash, Word32)]
refs = EndorserBlock -> [(TxHash, Word32)]
endorserBlockReferences EndorserBlock
eb
in WeHaveAgencyProof 'AsClient 'StIdle
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlockTxs)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(st' :: ps) (m :: * -> *) a.
(StateTokenI st, StateTokenI st', ActiveState st,
Outstanding pl ~ 'Z, OutstandingSenders pl ~ 'Z) =>
WeHaveAgencyProof pr st
-> Message ps st st'
-> Peer ps pr pl st' m a
-> Peer ps pr pl st m a
Yield ReflRelativeAgency 'ClientAgency 'WeHaveAgency 'WeHaveAgency
WeHaveAgencyProof 'AsClient 'StIdle
forall (r :: RelativeAgency). ReflRelativeAgency 'ClientAgency r r
ReflClientAgency (LeiosPoint
-> TxBitmaps
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlockTxs)
forall point eb tx.
point
-> TxBitmaps
-> Message (LeiosFetch point eb tx) 'StIdle ('StBusy 'StBlockTxs)
MsgLeiosBlockTxsRequest LeiosPoint
point ([Int] -> TxBitmaps
bitmapsNaming [Int
0 .. [(TxHash, Word32)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(TxHash, Word32)]
refs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1])) (Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlockTxs)
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
(StateTokenI st, ActiveState st, Outstanding pl ~ 'Z,
OutstandingSenders pl ~ 'Z) =>
TheyHaveAgencyProof pr st
-> (forall (st' :: ps). Message ps st st' -> Peer ps pr pl st' m a)
-> Peer ps pr pl st m a
Await ReflRelativeAgency 'ServerAgency 'TheyHaveAgency 'TheyHaveAgency
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlockTxs)
forall (r :: RelativeAgency). ReflRelativeAgency 'ServerAgency r r
ReflServerAgency ((forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
())
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ \case
MsgLeiosBlockTxs Vector LeiosTx
txs ->
FetchBack
-> [[Char]]
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
settling FetchBack
offer ([[Char]]
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> [[Char]]
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$
[ [Char]
"served the closure of " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Hash HASH EraIndependentEbReferences -> [Char]
forall a. Show a => a -> [Char]
show (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
eb)
| EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
eb Hash HASH EraIndependentEbReferences
-> Hash HASH EraIndependentEbReferences -> Bool
forall a. Eq a => a -> a -> Bool
/= LeiosPoint -> Hash HASH EraIndependentEbReferences
pointEbHash LeiosPoint
point
]
[[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [ [Char]
"served transactions that do not match the body"
| [(LeiosTx -> TxHash
hashLeiosTx LeiosTx
tx, Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length (LeiosTx -> ByteString
leiosTxBytes LeiosTx
tx))) | LeiosTx
tx <- Vector LeiosTx -> [LeiosTx]
forall a. Vector a -> [a]
V.toList Vector LeiosTx
txs]
[(TxHash, Word32)] -> [(TxHash, Word32)] -> Bool
forall a. Eq a => a -> a -> Bool
/= [(TxHash, Word32)]
refs
]
where
settling :: FetchBack
-> [[Char]]
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
settling FetchBack
offer [[Char]]
whys = IOSim
s
(Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
m (Peer ps pr pl st m a) -> Peer ps pr pl st m a
Effect (IOSim
s
(Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> IOSim
s
(Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ StrictTQueue (IOSim s) FetchBack
-> (FetchBack -> [[Char]] -> IOSim s ())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall s.
StrictTQueue (IOSim s) FetchBack
-> (FetchBack -> [[Char]] -> IOSim s ()) -> EnvClient s
fetchingBack StrictTQueue (IOSim s) FetchBack
toFetch FetchBack -> [[Char]] -> IOSim s ()
settle Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
-> IOSim s ()
-> IOSim
s
(Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
forall a b. a -> IOSim s b -> IOSim s a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FetchBack -> [[Char]] -> IOSim s ()
settle FetchBack
offer (([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map ((FetchBack -> [Char]
forall a. Show a => a -> [Char]
show FetchBack
offer [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
": ") [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<>) [[Char]]
whys)
requestingBody :: LeiosPoint -> (EndorserBlock -> EnvClient s) -> EnvClient s
requestingBody :: forall s.
LeiosPoint -> (EndorserBlock -> EnvClient s) -> EnvClient s
requestingBody LeiosPoint
point EndorserBlock -> EnvClient s
k =
WeHaveAgencyProof 'AsClient 'StIdle
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlock)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
-> EnvClient s
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(st' :: ps) (m :: * -> *) a.
(StateTokenI st, StateTokenI st', ActiveState st,
Outstanding pl ~ 'Z, OutstandingSenders pl ~ 'Z) =>
WeHaveAgencyProof pr st
-> Message ps st st'
-> Peer ps pr pl st' m a
-> Peer ps pr pl st m a
Yield ReflRelativeAgency 'ClientAgency 'WeHaveAgency 'WeHaveAgency
WeHaveAgencyProof 'AsClient 'StIdle
forall (r :: RelativeAgency). ReflRelativeAgency 'ClientAgency r r
ReflClientAgency (LeiosPoint
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlock)
forall point eb tx.
point
-> Message (LeiosFetch point eb tx) 'StIdle ('StBusy 'StBlock)
MsgLeiosBlockRequest LeiosPoint
point) (Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
-> EnvClient s)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
-> EnvClient s
forall a b. (a -> b) -> a -> b
$
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlock)
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlock)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
(StateTokenI st, ActiveState st, Outstanding pl ~ 'Z,
OutstandingSenders pl ~ 'Z) =>
TheyHaveAgencyProof pr st
-> (forall (st' :: ps). Message ps st st' -> Peer ps pr pl st' m a)
-> Peer ps pr pl st m a
Await ReflRelativeAgency 'ServerAgency 'TheyHaveAgency 'TheyHaveAgency
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlock)
forall (r :: RelativeAgency). ReflRelativeAgency 'ServerAgency r r
ReflServerAgency ((forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlock)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
())
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlock)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ \case
MsgLeiosBlock Serialised EndorserBlock
bytes ->
EndorserBlock -> EnvClient s
k (EndorserBlock -> EnvClient s) -> EndorserBlock -> EnvClient s
forall a b. (a -> b) -> a -> b
$ (DecoderError -> EndorserBlock)
-> (EndorserBlock -> EndorserBlock)
-> Either DecoderError EndorserBlock
-> EndorserBlock
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ([Char] -> EndorserBlock
forall a. HasCallStack => [Char] -> a
error ([Char] -> EndorserBlock)
-> (DecoderError -> [Char]) -> DecoderError -> EndorserBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DecoderError -> [Char]
forall a. Show a => a -> [Char]
show) EndorserBlock -> EndorserBlock
forall a. a -> a
id (Either DecoderError EndorserBlock -> EndorserBlock)
-> Either DecoderError EndorserBlock -> EndorserBlock
forall a b. (a -> b) -> a -> b
$ Proxy DijkstraEra
-> Serialised EndorserBlock -> Either DecoderError EndorserBlock
forall era (proxy :: * -> *).
Era era =>
proxy era
-> Serialised EndorserBlock -> Either DecoderError EndorserBlock
deserialiseEndorserBlock (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @DijkstraEra) Serialised EndorserBlock
bytes
feedingLeiosNotifyServer ::
NodeUnderTest (IOSim s) ->
StrictTQueue
(IOSim s)
(Message (LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote) LN.StBusy LN.StIdle) ->
Channel (IOSim s) ByteString ->
IOSim s ()
feedingLeiosNotifyServer :: forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications Channel (IOSim s) ByteString
chan = do
server <-
IOSim s WhetherExcessiveRequests
-> STM
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> IOSim
s
(LeiosNotifyServerPeerLookahead
LeiosPoint (Header LeiosTestBlock) LeiosVote (IOSim s))
forall (m :: * -> *) point announcement vote.
(MonadThrow m, MonadSTM m) =>
m WhetherExcessiveRequests
-> STM
m (Message (LeiosNotify point announcement vote) 'StBusy 'StIdle)
-> m (LeiosNotifyServerPeerLookahead point announcement vote m)
leiosNotifyServerPeerLookahead
(WhetherExcessiveRequests -> IOSim s WhetherExcessiveRequests
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure WhetherExcessiveRequests
NotExcessiveRequests)
(StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> STM
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
forall (m :: * -> *) a. MonadSTM m => StrictTQueue m a -> STM m a
readTQueue StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications)
void $
runLookaheadFixedSenderPeerWithLimits
nullTracer
(envLeiosNotifyCodec node)
(byteLimitsLeiosNotify (fromIntegral . BSL.length))
timeLimitsLeiosNotify
chan
server
servingFetched :: NodeUnderTest (IOSim s) -> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched :: forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched = EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
serving EndorserBlock
fetchedEb Vector LeiosTx
fetchedTxs
serving ::
EndorserBlock ->
V.Vector LeiosTx ->
NodeUnderTest (IOSim s) ->
Channel (IOSim s) ByteString ->
IOSim s ()
serving :: forall s.
EndorserBlock
-> Vector LeiosTx
-> NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString
-> IOSim s ()
serving EndorserBlock
eb Vector LeiosTx
txs NodeUnderTest (IOSim s)
node Channel (IOSim s) ByteString
chan =
((), Maybe ByteString) -> ()
forall a b. (a, b) -> a
fst
(((), Maybe ByteString) -> ())
-> IOSim s ((), Maybe ByteString) -> IOSim s ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
-> Channel (IOSim s) ByteString
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsServer
'NonPipelined
'StIdle
(IOSim s)
()
-> IOSim s ((), Maybe ByteString)
forall ps (st :: ps) (pr :: PeerRole) failure bytes (m :: * -> *)
a.
(MonadEvaluate m, MonadThrow m, ShowProxy ps,
forall (st' :: ps) stok. (stok ~ StateToken st') => Show stok,
NFData a, NFData failure, Show failure) =>
Tracer m (TraceSendRecv ps)
-> Codec ps failure m bytes
-> Channel m bytes
-> Peer ps pr 'NonPipelined st m a
-> m (a, Maybe bytes)
runPeer Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall (m :: * -> *) a. Monad m => Tracer m a
nullTracer (NodeUnderTest (IOSim s)
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
forall s. NodeUnderTest (IOSim s) -> LeiosFetchCodec s
envLeiosFetchCodec NodeUnderTest (IOSim s)
node) Channel (IOSim s) ByteString
chan (LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsServer
'NonPipelined
'StIdle
(IOSim s)
()
forall point eb tx (m :: * -> *).
Functor m =>
LeiosFetchRequestHandler point eb tx m
-> LeiosFetchServerPeer point eb tx m ()
leiosFetchServerPeer (EndorserBlock
-> Vector LeiosTx
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx (IOSim s)
forall (m :: * -> *).
Monad m =>
EndorserBlock
-> Vector LeiosTx
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx m
serveEb EndorserBlock
eb Vector LeiosTx
txs))
servingChain :: NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
servingChain :: forall s.
NodeUnderTest (IOSim s) -> EnvChain (IOSim s) -> EnvPeer (IOSim s)
servingChain NodeUnderTest (IOSim s)
node EnvChain (IOSim s)
chain =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = EnvChain (IOSim s)
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
EnvChain (IOSim s)
-> ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
chainSyncServerOf EnvChain (IOSim s)
chain
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = \Channel (IOSim s) ByteString
_chan -> STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) ()
forall a. STM (IOSim s) a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
silentLeiosFetchServer NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
offersFetched :: NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s Bool
offersFetched :: forall s. NodeUnderTest (IOSim s) -> PeerAddr -> IOSim s Bool
offersFetched NodeUnderTest (IOSim s)
node PeerAddr
addr = STM (IOSim s) Bool -> IOSim s Bool
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
IOLike.atomically (STM (IOSim s) Bool -> IOSim s Bool)
-> STM (IOSim s) Bool -> IOSim s Bool
forall a b. (a -> b) -> a -> b
$ do
peers <- StrictTVar
(IOSim s)
(Map
(LeiosPeerLifetimeId (ConnectionId PeerAddr))
(LeiosFetchPeer (IOSim s) LeiosTestBlock))
-> STM
(IOSim s)
(Map
(LeiosPeerLifetimeId (ConnectionId PeerAddr))
(LeiosFetchPeer (IOSim s) LeiosTestBlock))
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
IOLike.readTVar (LeiosFetchKernel (IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
-> StrictTVar
(IOSim s)
(Map
(LeiosPeerLifetimeId (ConnectionId PeerAddr))
(LeiosFetchPeer (IOSim s) LeiosTestBlock))
forall (m :: * -> *) peer blk.
LeiosFetchKernel m peer blk
-> StrictTVar
m (Map (LeiosPeerLifetimeId peer) (LeiosFetchPeer m blk))
lfkPeers (NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
-> LeiosFetchKernel
(IOSim s) (ConnectionId PeerAddr) LeiosTestBlock
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk
-> LeiosFetchKernel m (ConnectionId addrNTN) blk
getLeiosFetchKernel (NodeUnderTest (IOSim s)
-> NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
forall (m :: * -> *).
NodeUnderTest m
-> NodeKernel m PeerAddr (ConnectionId ()) LeiosTestBlock
nodeKernel NodeUnderTest (IOSim s)
node)))
case [peer | (MkLeiosPeerLifetimeId connId _, peer) <- Map.toList peers, remoteAddress connId == addr] of
[] -> Bool -> STM s Bool
forall a. a -> STM s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
LeiosFetchPeer (IOSim s) LeiosTestBlock
peer : [LeiosFetchPeer (IOSim s) LeiosTestBlock]
_ -> LeiosPoint -> Map LeiosPoint PeerOffer -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member LeiosPoint
fetchedPoint (Map LeiosPoint PeerOffer -> Bool)
-> STM s (Map LeiosPoint PeerOffer) -> STM s Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictTVar (IOSim s) (Map LeiosPoint PeerOffer)
-> STM (IOSim s) (Map LeiosPoint PeerOffer)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
IOLike.readTVar (LeiosFetchPeer (IOSim s) LeiosTestBlock
-> StrictTVar (IOSim s) (Map LeiosPoint PeerOffer)
forall (m :: * -> *) blk.
LeiosFetchPeer m blk -> StrictTVar m (Map LeiosPoint PeerOffer)
lfpOfferings LeiosFetchPeer (IOSim s) LeiosTestBlock
peer)
relayedOf ::
Message (LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote) LN.StBusy LN.StIdle -> Relayed
relayedOf :: Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> Relayed
relayedOf = \case
MsgLeiosBlockAnnouncement Header LeiosTestBlock
_hdr -> Relayed
RelayedAnnouncement
MsgLeiosBlockOffer LeiosPoint
point Word32
size -> LeiosPoint -> Word32 -> Relayed
RelayedBlockOffer LeiosPoint
point Word32
size
MsgLeiosBlockTxsOffer LeiosPoint
point -> LeiosPoint -> Relayed
RelayedBlockTxsOffer LeiosPoint
point
MsgLeiosVotes NonEmpty LeiosVote
_votes -> Relayed
RelayedVotes
Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
R:MessageLeiosNotifyfromto
LeiosPoint (Header LeiosTestBlock) LeiosVote 'StBusy 'StIdle
MsgCanceled -> Relayed
RelayedVotes
serveEb ::
Monad m =>
EndorserBlock ->
V.Vector LeiosTx ->
LeiosFetchRequestHandler LeiosPoint (Serialised EndorserBlock) LeiosTx m
serveEb :: forall (m :: * -> *).
Monad m =>
EndorserBlock
-> Vector LeiosTx
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx m
serveEb EndorserBlock
eb Vector LeiosTx
txs = (forall (st :: LeiosFetchBusy
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy st)
-> m (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle))
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx m
forall point eb tx (m :: * -> *).
(forall (st :: LeiosFetchBusy point eb tx).
Message (LeiosFetch point eb tx) 'StIdle ('StBusy st)
-> m (Message (LeiosFetch point eb tx) ('StBusy st) 'StIdle))
-> LeiosFetchRequestHandler point eb tx m
MkLeiosFetchRequestHandler ((forall (st :: LeiosFetchBusy
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy st)
-> m (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle))
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx m)
-> (forall (st :: LeiosFetchBusy
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy st)
-> m (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle))
-> LeiosFetchRequestHandler
LeiosPoint (Serialised EndorserBlock) LeiosTx m
forall a b. (a -> b) -> a -> b
$ \case
MsgLeiosBlockRequest LeiosPoint
_point -> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle
-> m (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Serialised EndorserBlock
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlock)
'StIdle
forall eb point tx.
eb -> Message (LeiosFetch point eb tx) ('StBusy 'StBlock) 'StIdle
MsgLeiosBlock (EndorserBlock -> Serialised EndorserBlock
serialiseEndorserBlock EndorserBlock
eb))
MsgLeiosBlockTxsRequest LeiosPoint
_point TxBitmaps
bitmaps ->
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle
-> m (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle
-> m (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle))
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle
-> m (Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy st)
'StIdle)
forall a b. (a -> b) -> a -> b
$ Vector LeiosTx
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
'StIdle
forall tx point eb.
Vector tx
-> Message (LeiosFetch point eb tx) ('StBusy 'StBlockTxs) 'StIdle
MsgLeiosBlockTxs (Vector LeiosTx
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
'StIdle)
-> Vector LeiosTx
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
'StIdle
forall a b. (a -> b) -> a -> b
$ [LeiosTx] -> Vector LeiosTx
forall a. [a] -> Vector a
V.fromList ([LeiosTx] -> Vector LeiosTx) -> [LeiosTx] -> Vector LeiosTx
forall a b. (a -> b) -> a -> b
$ (Int -> Maybe LeiosTx) -> [Int] -> [LeiosTx]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Vector LeiosTx
txs Vector LeiosTx -> Int -> Maybe LeiosTx
forall a. Vector a -> Int -> Maybe a
V.!?) (TxBitmaps -> [Int]
bitmapToOffsets TxBitmaps
bitmaps)
relayedFetchedAt :: LeiosPoint -> [Relayed]
relayedFetchedAt :: LeiosPoint -> [Relayed]
relayedFetchedAt LeiosPoint
point =
[ Relayed
RelayedAnnouncement
, LeiosPoint -> Word32 -> Relayed
RelayedBlockOffer LeiosPoint
point (EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb)
, LeiosPoint -> Relayed
RelayedBlockTxsOffer LeiosPoint
point
]
immutableTipInSlot5 :: Point LeiosTestBlock
immutableTipInSlot5 :: Point LeiosTestBlock
immutableTipInSlot5 = LeiosTestBlock -> Point LeiosTestBlock
forall block. HasHeader block => block -> Point block
blockPoint (LeiosTestBlock -> Point LeiosTestBlock)
-> LeiosTestBlock -> Point LeiosTestBlock
forall a b. (a -> b) -> a -> b
$ (LeiosTestBlock -> LeiosTestBlock)
-> LeiosTestBlock -> [LeiosTestBlock]
forall a. (a -> a) -> a -> [a]
iterate LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock (Word64 -> LeiosTestBlock
firstLeiosBlock Word64
9) [LeiosTestBlock] -> Int -> LeiosTestBlock
forall a. HasCallStack => [a] -> Int -> a
!! Int
4
announcingLater :: LeiosTestBlock
announcingLater :: LeiosTestBlock
announcingLater =
Hash HASH EraIndependentEbReferences
-> Word32 -> LeiosTestBlock -> LeiosTestBlock
setAnnouncement
(EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb)
(EndorserBlock -> Word32
encodeEndorserBlockSize EndorserBlock
fetchedEb)
((LeiosTestBlock -> LeiosTestBlock)
-> LeiosTestBlock -> [LeiosTestBlock]
forall a. (a -> a) -> a -> [a]
iterate LeiosTestBlock -> LeiosTestBlock
successorLeiosBlock (Word64 -> LeiosTestBlock
firstLeiosBlock Word64
10) [LeiosTestBlock] -> Int -> LeiosTestBlock
forall a. HasCallStack => [a] -> Int -> a
!! Int
14)
laterPoint :: LeiosPoint
laterPoint :: LeiosPoint
laterPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingLater) (EndorserBlock -> Hash HASH EraIndependentEbReferences
endorserBlockHash EndorserBlock
fetchedEb)
prop_listenerReach :: Property
prop_listenerReach :: Property
prop_listenerReach =
Int -> Property -> Property
forall prop. Testable prop => Int -> prop -> Property
withNumTests Int
50 (Property -> Property) -> Property -> Property
forall a b. (a -> b) -> a -> b
$
Gen (Point LeiosTestBlock, NominalDiffTime, DiffTime)
-> ((Point LeiosTestBlock, NominalDiffTime, DiffTime) -> Property)
-> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen (Point LeiosTestBlock, NominalDiffTime, DiffTime)
genReach (((Point LeiosTestBlock, NominalDiffTime, DiffTime) -> Property)
-> Property)
-> ((Point LeiosTestBlock, NominalDiffTime, DiffTime) -> Property)
-> Property
forall a b. (a -> b) -> a -> b
$ \(Point LeiosTestBlock
immTip, NominalDiffTime
offset, DiffTime
age) ->
let expected :: [Relayed]
expected
| DiffTime
age DiffTime -> DiffTime -> Bool
forall a. Ord a => a -> a -> Bool
<= DiffTime
maxAgeSend DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
- DiffTime
1 = LeiosPoint -> [Relayed]
relayedFetchedAt LeiosPoint
laterPoint
| Bool
otherwise = []
in IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO Property -> Property) -> IO Property -> Property
forall a b. (a -> b) -> a -> b
$ do
relays <-
DiffTime -> (forall s. IOSim s [Relayed]) -> IO [Relayed]
forall a. DiffTime -> (forall s. IOSim s a) -> IO a
runSimFinishingWithin
(NominalDiffTime -> DiffTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac (LeiosAnnouncementAgeLimits -> NominalDiffTime
maxAnnouncementAgeRecv LeiosAnnouncementAgeLimits
defaultLeiosAnnouncementAgeLimits) DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ DiffTime
100)
(Point LeiosTestBlock
-> NominalDiffTime -> DiffTime -> Int -> IOSim s [Relayed]
forall s.
Point LeiosTestBlock
-> NominalDiffTime -> DiffTime -> Int -> IOSim s [Relayed]
listenerReach Point LeiosTestBlock
immTip NominalDiffTime
offset DiffTime
age ([Relayed] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Relayed]
expected))
pure $
tabulate "listener connects" [connects age] $
tabulate "listener's clock" [clock offset] $
relays === expected
where
connects :: DiffTime -> [Char]
connects DiffTime
age
| DiffTime
age DiffTime -> DiffTime -> Bool
forall a. Ord a => a -> a -> Bool
< DiffTime
0 = [Char]
"before the announcement"
| DiffTime
age DiffTime -> DiffTime -> Bool
forall a. Ord a => a -> a -> Bool
<= DiffTime
maxAgeSend DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
- DiffTime
1 = [Char]
"while the node relays it"
| Bool
otherwise = [Char]
"once the node no longer relays it"
clock :: a -> [Char]
clock a
offset
| a
offset a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 = [Char]
"the node's"
| a -> a
forall a. Num a => a -> a
abs a
offset a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== NominalDiffTime -> a
forall a b. (Real a, Fractional b) => a -> b
realToFrac (ClockSkew -> NominalDiffTime
InFutureCheck.unClockSkew ClockSkew
InFutureCheck.defaultClockSkew) =
[Char]
"at the allowed skew"
| Bool
otherwise = [Char]
"within the allowed skew"
genReach :: Gen (Point LeiosTestBlock, NominalDiffTime, DiffTime)
genReach :: Gen (Point LeiosTestBlock, NominalDiffTime, DiffTime)
genReach = do
immTip <- [Point LeiosTestBlock] -> Gen (Point LeiosTestBlock)
forall a. HasCallStack => [a] -> Gen a
elements [Point LeiosTestBlock
forall {k} (block :: k). Point block
GenesisPoint, Point LeiosTestBlock
immutableTipInSlot5]
offset <- realToFrac <$> oneof [elements [-skew, 0, skew], choose (-skew, skew)]
age <-
fromInteger
<$> oneof
[ choose (-slot, -1)
, choose (0, lastRelayed)
, elements [lastRelayed, firstUnrelayed]
, choose (firstUnrelayed, 2 * firstUnrelayed)
]
pure (immTip, offset, age)
where
skew :: Double
skew :: Double
skew = NominalDiffTime -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac (ClockSkew -> NominalDiffTime
InFutureCheck.unClockSkew ClockSkew
InFutureCheck.defaultClockSkew)
slot :: Integer
slot = Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (SlotNo -> Word64
unSlotNo (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingLater))
lastRelayed :: Integer
lastRelayed = DiffTime -> Integer
forall b. Integral b => DiffTime -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (DiffTime
maxAgeSend DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
- DiffTime
1)
firstUnrelayed :: Integer
firstUnrelayed = DiffTime -> Integer
forall b. Integral b => DiffTime -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (DiffTime
maxAgeSend DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ NominalDiffTime -> DiffTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac NominalDiffTime
leiosDeadlinePrunerInterval DiffTime -> DiffTime -> DiffTime
forall a. Num a => a -> a -> a
+ DiffTime
1)
listenerReach :: Point LeiosTestBlock -> NominalDiffTime -> DiffTime -> Int -> IOSim s [Relayed]
listenerReach :: forall s.
Point LeiosTestBlock
-> NominalDiffTime -> DiffTime -> Int -> IOSim s [Relayed]
listenerReach Point LeiosTestBlock
immTip NominalDiffTime
offset DiffTime
age Int
expected = (NodeUnderTest (IOSim s) -> IOSim s [Relayed]) -> IOSim s [Relayed]
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed])
-> (NodeUnderTest (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
next <- LeiosAcquisitions (IOSim s)
-> IOSim s (STM (IOSim s) LeiosAcquisition)
forall (m :: * -> *).
LeiosAcquisitions m -> m (STM m LeiosAcquisition)
subscribeLeiosAcquisitions (NodeUnderTest (IOSim s) -> LeiosAcquisitions (IOSim s)
forall (m :: * -> *). NodeUnderTest m -> LeiosAcquisitions m
nodeLeiosAcquisitions NodeUnderTest (IOSim s)
node)
notifications <- newTQueueIO
listener <- newListenerWith node immTip offset
let
onset = DiffTime -> Time
Time (Word64 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (SlotNo -> Word64
unSlotNo (LeiosTestBlock -> SlotNo
forall b. HasHeader b => b -> SlotNo
blockSlot LeiosTestBlock
announcingLater)))
waitUntil Time
t = m Time
forall (m :: * -> *). MonadMonotonicTime m => m Time
getMonotonicTime m Time -> (Time -> m ()) -> m ()
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= DiffTime -> m ()
forall (m :: * -> *). MonadDelay m => DiffTime -> m ()
threadDelay (DiffTime -> m ()) -> (Time -> DiffTime) -> Time -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Time -> Time -> DiffTime
diffTime Time
t
holder = do
Time -> IOSim s ()
forall {m :: * -> *}. MonadDelay m => Time -> m ()
waitUntil Time
onset
STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM (IOSim s) () -> IOSim s ()) -> STM (IOSim s) () -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ (Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ())
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
-> STM (IOSim s) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle
-> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTQueue m a -> a -> STM m ()
writeTQueue StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications) (EndorserBlock
-> LeiosTestBlock
-> [Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle]
announcingAndOffering EndorserBlock
fetchedEb LeiosTestBlock
announcingLater)
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s ())
-> IOSim s ()
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
1) (NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> EnvPeer (IOSim s)
holdingFetched NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications) ((NodeVsEnvConnection (IOSim s) -> IOSim s ()) -> IOSim s ())
-> (NodeVsEnvConnection (IOSim s) -> IOSim s ()) -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_holderConn ->
Int -> IOSim s LeiosAcquisition -> IOSim s ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
2 (IOSim s LeiosAcquisition -> IOSim s ())
-> IOSim s LeiosAcquisition -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ STM (IOSim s) LeiosAcquisition -> IOSim s LeiosAcquisition
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) LeiosAcquisition
STM s LeiosAcquisition
next
withAsync holder $ \Async (IOSim s) ()
_ -> do
Time -> IOSim s ()
forall {m :: * -> *}. MonadDelay m => Time -> m ()
waitUntil (DiffTime -> Time -> Time
addTime DiffTime
age Time
onset)
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
2) (NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
listening NodeUnderTest (IOSim s)
node Listener s
listener) ((NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed])
-> (NodeVsEnvConnection (IOSim s) -> IOSim s [Relayed])
-> IOSim s [Relayed]
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
_listenerConn ->
Listener s -> Int -> IOSim s [Relayed]
forall s. Listener s -> Int -> IOSim s [Relayed]
relayedBy Listener s
listener Int
expected
maxAgeSend :: DiffTime
maxAgeSend :: DiffTime
maxAgeSend = NominalDiffTime -> DiffTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac (LeiosAnnouncementAgeLimits -> NominalDiffTime
maxAnnouncementAgeSend LeiosAnnouncementAgeLimits
defaultLeiosAnnouncementAgeLimits)
holdingFetched ::
NodeUnderTest (IOSim s) ->
StrictTQueue
(IOSim s)
(Message (LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote) LN.StBusy LN.StIdle) ->
EnvPeer (IOSim s)
holdingFetched :: forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> EnvPeer (IOSim s)
holdingFetched NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Channel (IOSim s) ByteString
-> IOSim s ()
feedingLeiosNotifyServer NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
servingFetched NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
}
holdingFetchedListening ::
NodeUnderTest (IOSim s) ->
StrictTQueue
(IOSim s)
(Message (LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote) LN.StBusy LN.StIdle) ->
Listener s ->
EnvPeer (IOSim s)
holdingFetchedListening :: forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> Listener s
-> EnvPeer (IOSim s)
holdingFetchedListening NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications Listener s
listener =
(NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> EnvPeer (IOSim s)
forall s.
NodeUnderTest (IOSim s)
-> StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
-> EnvPeer (IOSim s)
holdingFetched NodeUnderTest (IOSim s)
node StrictTQueue
(IOSim s)
(Message
(LeiosNotify LeiosPoint (Header LeiosTestBlock) LeiosVote)
'StBusy
'StIdle)
notifications)
{ epLeiosNotifyClient = Just (lsNotifyClient listener)
, epLeiosFetchClient = Just (lsFetchClient listener)
}
listening :: NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
listening :: forall s.
NodeUnderTest (IOSim s) -> Listener s -> EnvPeer (IOSim s)
listening NodeUnderTest (IOSim s)
node Listener s
listener =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = \Channel (IOSim s) ByteString
_chan -> STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) ()
forall a. STM (IOSim s) a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = (Channel (IOSim s) ByteString -> IOSim s ())
-> Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. a -> Maybe a
Just (Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
forall s. Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
lsNotifyClient Listener s
listener)
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
silentLeiosFetchServer NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = (Channel (IOSim s) ByteString -> IOSim s ())
-> Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. a -> Maybe a
Just (Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
forall s. Listener s -> Channel (IOSim s) ByteString -> IOSim s ()
lsFetchClient Listener s
listener)
}
data ServerOutcome = ServerEnded | ServerFailed String
deriving (ServerOutcome -> ServerOutcome -> Bool
(ServerOutcome -> ServerOutcome -> Bool)
-> (ServerOutcome -> ServerOutcome -> Bool) -> Eq ServerOutcome
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ServerOutcome -> ServerOutcome -> Bool
== :: ServerOutcome -> ServerOutcome -> Bool
$c/= :: ServerOutcome -> ServerOutcome -> Bool
/= :: ServerOutcome -> ServerOutcome -> Bool
Eq, Int -> ServerOutcome -> [Char] -> [Char]
[ServerOutcome] -> [Char] -> [Char]
ServerOutcome -> [Char]
(Int -> ServerOutcome -> [Char] -> [Char])
-> (ServerOutcome -> [Char])
-> ([ServerOutcome] -> [Char] -> [Char])
-> Show ServerOutcome
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> ServerOutcome -> [Char] -> [Char]
showsPrec :: Int -> ServerOutcome -> [Char] -> [Char]
$cshow :: ServerOutcome -> [Char]
show :: ServerOutcome -> [Char]
$cshowList :: [ServerOutcome] -> [Char] -> [Char]
showList :: [ServerOutcome] -> [Char] -> [Char]
Show)
type EnvClient s =
Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
AsClient
NonPipelined
StIdle
(IOSim s)
()
nodeServerAgainst :: EnvClient s -> IOSim s ServerOutcome
nodeServerAgainst :: forall s. EnvClient s -> IOSim s ServerOutcome
nodeServerAgainst EnvClient s
client = (NodeUnderTest (IOSim s) -> IOSim s ServerOutcome)
-> IOSim s ServerOutcome
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s ServerOutcome)
-> IOSim s ServerOutcome)
-> (NodeUnderTest (IOSim s) -> IOSim s ServerOutcome)
-> IOSim s ServerOutcome
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node -> do
NodeUnderTest (IOSim s) -> IOSim s ()
forall s. NodeUnderTest (IOSim s) -> IOSim s ()
holdHeldEb NodeUnderTest (IOSim s)
node
let envPeer :: EnvPeer (IOSim s)
envPeer =
EnvPeer
{ epChainSyncServer :: ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
epChainSyncServer = ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
forall s.
ChainSyncServer
(Header LeiosTestBlock)
(Point LeiosTestBlock)
(Tip LeiosTestBlock)
(IOSim s)
()
quietChainSyncServer
, epLeiosNotifyServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosNotifyServer = \Channel (IOSim s) ByteString
_chan -> STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically STM (IOSim s) ()
forall a. STM (IOSim s) a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
, epLeiosNotifyClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosNotifyClient = Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. Maybe a
Nothing
, epLeiosFetchServer :: Channel (IOSim s) ByteString -> IOSim s ()
epLeiosFetchServer = NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> Channel (IOSim s) ByteString -> IOSim s ()
refusingLeiosFetchServer NodeUnderTest (IOSim s)
node
, epLeiosFetchClient :: Maybe (Channel (IOSim s) ByteString -> IOSim s ())
epLeiosFetchClient = (Channel (IOSim s) ByteString -> IOSim s ())
-> Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a. a -> Maybe a
Just ((Channel (IOSim s) ByteString -> IOSim s ())
-> Maybe (Channel (IOSim s) ByteString -> IOSim s ()))
-> (Channel (IOSim s) ByteString -> IOSim s ())
-> Maybe (Channel (IOSim s) ByteString -> IOSim s ())
forall a b. (a -> b) -> a -> b
$ NodeUnderTest (IOSim s)
-> EnvClient s -> Channel (IOSim s) ByteString -> IOSim s ()
forall s.
NodeUnderTest (IOSim s)
-> EnvClient s -> Channel (IOSim s) ByteString -> IOSim s ()
runEnvClient NodeUnderTest (IOSim s)
node EnvClient s
client
}
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s ServerOutcome)
-> IOSim s ServerOutcome
forall s a.
NodeUnderTest (IOSim s)
-> PeerAddr
-> EnvPeer (IOSim s)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s a)
-> IOSim s a
withNodeVsEnvConnection NodeUnderTest (IOSim s)
node (Int -> PeerAddr
PeerAddr Int
1) EnvPeer (IOSim s)
envPeer ((NodeVsEnvConnection (IOSim s) -> IOSim s ServerOutcome)
-> IOSim s ServerOutcome)
-> (NodeVsEnvConnection (IOSim s) -> IOSim s ServerOutcome)
-> IOSim s ServerOutcome
forall a b. (a -> b) -> a -> b
$ \NodeVsEnvConnection (IOSim s)
conn -> do
server <- NodeVsEnvConnection (IOSim s)
-> IOSim s (STM (IOSim s) (Either SomeException ()))
forall s.
NodeVsEnvConnection (IOSim s)
-> IOSim s (STM (IOSim s) (Either SomeException ()))
nodeLeiosFetchServer NodeVsEnvConnection (IOSim s)
conn
atomically server >>= \case
Right () -> ServerOutcome -> IOSim s ServerOutcome
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerOutcome
ServerEnded
Left SomeException
e -> ServerOutcome -> IOSim s ServerOutcome
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ServerOutcome -> IOSim s ServerOutcome)
-> ServerOutcome -> IOSim s ServerOutcome
forall a b. (a -> b) -> a -> b
$ [Char] -> ServerOutcome
ServerFailed (SomeException -> [Char]
forall a. Show a => a -> [Char]
show SomeException
e)
runEnvClient :: NodeUnderTest (IOSim s) -> EnvClient s -> Channel (IOSim s) ByteString -> IOSim s ()
runEnvClient :: forall s.
NodeUnderTest (IOSim s)
-> EnvClient s -> Channel (IOSim s) ByteString -> IOSim s ()
runEnvClient NodeUnderTest (IOSim s)
node EnvClient s
client Channel (IOSim s) ByteString
chan = ((), Maybe ByteString) -> ()
forall a b. (a, b) -> a
fst (((), Maybe ByteString) -> ())
-> IOSim s ((), Maybe ByteString) -> IOSim s ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
-> Channel (IOSim s) ByteString
-> EnvClient s
-> IOSim s ((), Maybe ByteString)
forall ps (st :: ps) (pr :: PeerRole) failure bytes (m :: * -> *)
a.
(MonadEvaluate m, MonadThrow m, ShowProxy ps,
forall (st' :: ps) stok. (stok ~ StateToken st') => Show stok,
NFData a, NFData failure, Show failure) =>
Tracer m (TraceSendRecv ps)
-> Codec ps failure m bytes
-> Channel m bytes
-> Peer ps pr 'NonPipelined st m a
-> m (a, Maybe bytes)
runPeer Tracer
(IOSim s)
(TraceSendRecv
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx))
forall (m :: * -> *) a. Monad m => Tracer m a
nullTracer (NodeUnderTest (IOSim s)
-> Codec
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
DeserialiseFailure
(IOSim s)
ByteString
forall s. NodeUnderTest (IOSim s) -> LeiosFetchCodec s
envLeiosFetchCodec NodeUnderTest (IOSim s)
node) Channel (IOSim s) ByteString
chan EnvClient s
client
doneClient :: EnvClient s
doneClient :: forall s. EnvClient s
doneClient = WeHaveAgencyProof 'AsClient 'StIdle
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
'StDone
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StDone
(IOSim s)
()
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(st' :: ps) (m :: * -> *) a.
(StateTokenI st, StateTokenI st', ActiveState st,
Outstanding pl ~ 'Z, OutstandingSenders pl ~ 'Z) =>
WeHaveAgencyProof pr st
-> Message ps st st'
-> Peer ps pr pl st' m a
-> Peer ps pr pl st m a
Yield ReflRelativeAgency 'ClientAgency 'WeHaveAgency 'WeHaveAgency
WeHaveAgencyProof 'AsClient 'StIdle
forall (r :: RelativeAgency). ReflRelativeAgency 'ClientAgency r r
ReflClientAgency Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
'StDone
forall point eb tx.
Message (LeiosFetch point eb tx) 'StIdle 'StDone
MsgDone (Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StDone
(IOSim s)
()
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StDone
(IOSim s)
()
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StIdle
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ NobodyHasAgencyProof 'AsClient 'StDone
-> ()
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
'StDone
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
(StateTokenI st, StateAgency st ~ 'NobodyAgency,
Outstanding pl ~ 'Z, OutstandingSenders pl ~ 'Z) =>
NobodyHasAgencyProof pr st -> a -> Peer ps pr pl st m a
Done ReflRelativeAgency 'NobodyAgency 'NobodyHasAgency 'NobodyHasAgency
NobodyHasAgencyProof 'AsClient 'StDone
forall (r :: RelativeAgency). ReflRelativeAgency 'NobodyAgency r r
ReflNobodyAgency ()
data Reply = ReplyBlock (Serialised EndorserBlock) | ReplyTxs [LeiosTx]
deriving (Reply -> Reply -> Bool
(Reply -> Reply -> Bool) -> (Reply -> Reply -> Bool) -> Eq Reply
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Reply -> Reply -> Bool
== :: Reply -> Reply -> Bool
$c/= :: Reply -> Reply -> Bool
/= :: Reply -> Reply -> Bool
Eq, Int -> Reply -> [Char] -> [Char]
[Reply] -> [Char] -> [Char]
Reply -> [Char]
(Int -> Reply -> [Char] -> [Char])
-> (Reply -> [Char]) -> ([Reply] -> [Char] -> [Char]) -> Show Reply
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> Reply -> [Char] -> [Char]
showsPrec :: Int -> Reply -> [Char] -> [Char]
$cshow :: Reply -> [Char]
show :: Reply -> [Char]
$cshowList :: [Reply] -> [Char] -> [Char]
showList :: [Reply] -> [Char] -> [Char]
Show)
data Request
= RequestBlock !LeiosPoint
|
RequestTxs !LeiosPoint ![Int]
deriving Int -> Request -> [Char] -> [Char]
[Request] -> [Char] -> [Char]
Request -> [Char]
(Int -> Request -> [Char] -> [Char])
-> (Request -> [Char])
-> ([Request] -> [Char] -> [Char])
-> Show Request
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> Request -> [Char] -> [Char]
showsPrec :: Int -> Request -> [Char] -> [Char]
$cshow :: Request -> [Char]
show :: Request -> [Char]
$cshowList :: [Request] -> [Char] -> [Char]
showList :: [Request] -> [Char] -> [Char]
Show
prop_serverAnswers :: Property
prop_serverAnswers :: Property
prop_serverAnswers =
Gen [Request] -> ([Request] -> Property) -> Property
forall a prop.
(Show a, Testable prop) =>
Gen a -> (a -> prop) -> Property
forAll Gen [Request]
genRequests (([Request] -> Property) -> Property)
-> ([Request] -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \[Request]
requests -> IO Property -> Property
forall prop. Testable prop => IO prop -> Property
ioProperty (IO Property -> Property) -> IO Property -> Property
forall a b. (a -> b) -> a -> b
$ do
answers@(replies, outcome) <- (forall s. IOSim s ([Reply], ServerOutcome))
-> IO ([Reply], ServerOutcome)
forall a. (forall s. IOSim s a) -> IO a
runSimFinishing ([Request] -> IOSim s ([Reply], ServerOutcome)
forall s. [Request] -> IOSim s ([Reply], ServerOutcome)
nodeAnswers [Request]
requests)
pure $
tabulate "how the server ended" [ending outcome] $
tabulate "replies before then" [show (length replies)] $
answers === expectedAnswers requests
where
ending :: ServerOutcome -> [Char]
ending = \case
ServerOutcome
ServerEnded -> [Char]
"ended"
ServerFailed [Char]
e -> [Char]
"failed: " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
' ') [Char]
e
genRequests :: Gen [Request]
genRequests :: Gen [Request]
genRequests = do
n <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
0, Int
3)
replicateM n $ do
point <- elements [heldPoint, unknownPoint]
highest <- elements [last heldOffsets, last heldOffsets + 1, 130]
oneof
[ pure (RequestBlock point)
, RequestTxs point <$> (sublistOf [0 .. highest] `suchThat` (not . null))
]
expectedAnswers :: [Request] -> ([Reply], ServerOutcome)
expectedAnswers :: [Request] -> ([Reply], ServerOutcome)
expectedAnswers = [Reply] -> [Request] -> ([Reply], ServerOutcome)
go []
where
go :: [Reply] -> [Request] -> ([Reply], ServerOutcome)
go [Reply]
replies = \case
[] -> ([Reply] -> [Reply]
forall a. [a] -> [a]
reverse [Reply]
replies, ServerOutcome
ServerEnded)
RequestBlock LeiosPoint
point : [Request]
rest
| LeiosPoint
point LeiosPoint -> LeiosPoint -> Bool
forall a. Eq a => a -> a -> Bool
== LeiosPoint
heldPoint -> [Reply] -> [Request] -> ([Reply], ServerOutcome)
go (Serialised EndorserBlock -> Reply
ReplyBlock (EndorserBlock -> Serialised EndorserBlock
serialiseEndorserBlock EndorserBlock
heldEb) Reply -> [Reply] -> [Reply]
forall a. a -> [a] -> [a]
: [Reply]
replies) [Request]
rest
| Bool
otherwise -> ([Reply] -> [Reply]
forall a. [a] -> [a]
reverse [Reply]
replies, [Char] -> ServerOutcome
ServerFailed (ExnLeiosInvalidRequest -> [Char]
forall a. Show a => a -> [Char]
show (LeiosPoint -> ExnLeiosInvalidRequest
ExnLeiosUnknownBlockRequested LeiosPoint
point)))
RequestTxs LeiosPoint
point [Int]
offsets : [Request]
rest
| [Int] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
missing -> [Reply] -> [Request] -> ([Reply], ServerOutcome)
go ([LeiosTx] -> Reply
ReplyTxs ((Int -> LeiosTx) -> [Int] -> [LeiosTx]
forall a b. (a -> b) -> [a] -> [b]
map Int -> LeiosTx
heldTx [Int]
ascending) Reply -> [Reply] -> [Reply]
forall a. a -> [a] -> [a]
: [Reply]
replies) [Request]
rest
| Bool
otherwise -> ([Reply] -> [Reply]
forall a. [a] -> [a]
reverse [Reply]
replies, [Char] -> ServerOutcome
ServerFailed (ExnLeiosInvalidRequest -> [Char]
forall a. Show a => a -> [Char]
show (LeiosPoint -> [Int] -> ExnLeiosInvalidRequest
ExnLeiosUnknownTxsRequested LeiosPoint
point [Int]
missing)))
where
ascending :: [Int]
ascending = [Int] -> [Int]
forall a. Eq a => [a] -> [a]
List.nub ([Int] -> [Int]
forall a. Ord a => [a] -> [a]
List.sort [Int]
offsets)
missing :: [Int]
missing = [Int
offset | Int
offset <- [Int]
ascending, LeiosPoint
point LeiosPoint -> LeiosPoint -> Bool
forall a. Eq a => a -> a -> Bool
/= LeiosPoint
heldPoint Bool -> Bool -> Bool
|| Int
offset Int -> [Int] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Int]
heldOffsets]
nodeAnswers :: [Request] -> IOSim s ([Reply], ServerOutcome)
nodeAnswers :: forall s. [Request] -> IOSim s ([Reply], ServerOutcome)
nodeAnswers [Request]
requests = do
repliesVar <- [Reply] -> IOSim s (StrictTVar (IOSim s) [Reply])
forall (m :: * -> *) a. MonadSTM m => a -> m (StrictTVar m a)
newTVarIO []
outcome <- nodeServerAgainst (requestingClient requests repliesVar)
replies <- readTVarIO repliesVar
pure (reverse replies, outcome)
requestingClient :: [Request] -> StrictTVar (IOSim s) [Reply] -> EnvClient s
requestingClient :: forall s. [Request] -> StrictTVar (IOSim s) [Reply] -> EnvClient s
requestingClient [Request]
requests StrictTVar (IOSim s) [Reply]
repliesVar = case [Request]
requests of
[] -> EnvClient s
forall s. EnvClient s
doneClient
RequestBlock LeiosPoint
point : [Request]
rest ->
WeHaveAgencyProof 'AsClient 'StIdle
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlock)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
-> EnvClient s
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(st' :: ps) (m :: * -> *) a.
(StateTokenI st, StateTokenI st', ActiveState st,
Outstanding pl ~ 'Z, OutstandingSenders pl ~ 'Z) =>
WeHaveAgencyProof pr st
-> Message ps st st'
-> Peer ps pr pl st' m a
-> Peer ps pr pl st m a
Yield ReflRelativeAgency 'ClientAgency 'WeHaveAgency 'WeHaveAgency
WeHaveAgencyProof 'AsClient 'StIdle
forall (r :: RelativeAgency). ReflRelativeAgency 'ClientAgency r r
ReflClientAgency (LeiosPoint
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlock)
forall point eb tx.
point
-> Message (LeiosFetch point eb tx) 'StIdle ('StBusy 'StBlock)
MsgLeiosBlockRequest LeiosPoint
point) (Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
-> EnvClient s)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
-> EnvClient s
forall a b. (a -> b) -> a -> b
$
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlock)
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlock)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
(StateTokenI st, ActiveState st, Outstanding pl ~ 'Z,
OutstandingSenders pl ~ 'Z) =>
TheyHaveAgencyProof pr st
-> (forall (st' :: ps). Message ps st st' -> Peer ps pr pl st' m a)
-> Peer ps pr pl st m a
Await ReflRelativeAgency 'ServerAgency 'TheyHaveAgency 'TheyHaveAgency
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlock)
forall (r :: RelativeAgency). ReflRelativeAgency 'ServerAgency r r
ReflServerAgency ((forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlock)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
())
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlock)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlock)
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ \case
MsgLeiosBlock Serialised EndorserBlock
eb -> Reply -> [Request] -> EnvClient s
keep (Serialised EndorserBlock -> Reply
ReplyBlock Serialised EndorserBlock
eb) [Request]
rest
RequestTxs LeiosPoint
point [Int]
offsets : [Request]
rest ->
WeHaveAgencyProof 'AsClient 'StIdle
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlockTxs)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
-> EnvClient s
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(st' :: ps) (m :: * -> *) a.
(StateTokenI st, StateTokenI st', ActiveState st,
Outstanding pl ~ 'Z, OutstandingSenders pl ~ 'Z) =>
WeHaveAgencyProof pr st
-> Message ps st st'
-> Peer ps pr pl st' m a
-> Peer ps pr pl st m a
Yield ReflRelativeAgency 'ClientAgency 'WeHaveAgency 'WeHaveAgency
WeHaveAgencyProof 'AsClient 'StIdle
forall (r :: RelativeAgency). ReflRelativeAgency 'ClientAgency r r
ReflClientAgency (LeiosPoint
-> TxBitmaps
-> Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'StIdle
('StBusy 'StBlockTxs)
forall point eb tx.
point
-> TxBitmaps
-> Message (LeiosFetch point eb tx) 'StIdle ('StBusy 'StBlockTxs)
MsgLeiosBlockTxsRequest LeiosPoint
point ([Int] -> TxBitmaps
bitmapsNaming [Int]
offsets)) (Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
-> EnvClient s)
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
-> EnvClient s
forall a b. (a -> b) -> a -> b
$
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlockTxs)
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
(StateTokenI st, ActiveState st, Outstanding pl ~ 'Z,
OutstandingSenders pl ~ 'Z) =>
TheyHaveAgencyProof pr st
-> (forall (st' :: ps). Message ps st st' -> Peer ps pr pl st' m a)
-> Peer ps pr pl st m a
Await ReflRelativeAgency 'ServerAgency 'TheyHaveAgency 'TheyHaveAgency
TheyHaveAgencyProof 'AsClient ('StBusy 'StBlockTxs)
forall (r :: RelativeAgency). ReflRelativeAgency 'ServerAgency r r
ReflServerAgency ((forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
())
-> (forall (st' :: LeiosFetch
LeiosPoint (Serialised EndorserBlock) LeiosTx).
Message
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
('StBusy 'StBlockTxs)
st'
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
st'
(IOSim s)
())
-> Peer
(LeiosFetch LeiosPoint (Serialised EndorserBlock) LeiosTx)
'AsClient
'NonPipelined
('StBusy 'StBlockTxs)
(IOSim s)
()
forall a b. (a -> b) -> a -> b
$ \case
MsgLeiosBlockTxs Vector LeiosTx
txs -> Reply -> [Request] -> EnvClient s
keep ([LeiosTx] -> Reply
ReplyTxs (Vector LeiosTx -> [LeiosTx]
forall a. Vector a -> [a]
V.toList Vector LeiosTx
txs)) [Request]
rest
where
keep :: Reply -> [Request] -> EnvClient s
keep Reply
reply [Request]
rest =
IOSim s (EnvClient s) -> EnvClient s
forall ps (pr :: PeerRole) (pl :: IsPipelined ps) (st :: ps)
(m :: * -> *) a.
m (Peer ps pr pl st m a) -> Peer ps pr pl st m a
Effect (IOSim s (EnvClient s) -> EnvClient s)
-> IOSim s (EnvClient s) -> EnvClient s
forall a b. (a -> b) -> a -> b
$ [Request] -> StrictTVar (IOSim s) [Reply] -> EnvClient s
forall s. [Request] -> StrictTVar (IOSim s) [Reply] -> EnvClient s
requestingClient [Request]
rest StrictTVar (IOSim s) [Reply]
repliesVar EnvClient s -> IOSim s () -> IOSim s (EnvClient s)
forall a b. a -> IOSim s b -> IOSim s a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ STM (IOSim s) () -> IOSim s ()
forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (StrictTVar (IOSim s) [Reply]
-> ([Reply] -> [Reply]) -> STM (IOSim s) ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar (IOSim s) [Reply]
repliesVar (Reply
reply Reply -> [Reply] -> [Reply]
forall a. a -> [a] -> [a]
:))
bitmapsNaming :: [Int] -> TxBitmaps
bitmapsNaming :: [Int] -> TxBitmaps
bitmapsNaming [Int]
offsets =
Map Word16 Word64 -> TxBitmaps
forall k a. Map k a -> [(k, a)]
Map.toList (Map Word16 Word64 -> TxBitmaps) -> Map Word16 Word64 -> TxBitmaps
forall a b. (a -> b) -> a -> b
$
(Word64 -> Word64 -> Word64) -> TxBitmaps -> Map Word16 Word64
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith
Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
(.|.)
[(Int -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
offset Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
64), Int -> Word64
forall a. Bits a => Int -> a
Bits.bit (Int
63 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
offset Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
64)) | Int
offset <- [Int]
offsets]
heldEb :: EndorserBlock
heldEb :: EndorserBlock
heldEb =
[(TxHash, Word32)] -> EndorserBlock
mkEndorserBlock ([(TxHash, Word32)] -> EndorserBlock)
-> [(TxHash, Word32)] -> EndorserBlock
forall a b. (a -> b) -> a -> b
$
[(Int -> TxHash
heldTxHash Int
i, Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length (Int -> ByteString
heldTxBytes Int
i))) | Int
i <- [Int
0 .. Int
69]]
heldPoint :: LeiosPoint
heldPoint :: LeiosPoint
heldPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint SlotNo
1 (ShortByteString -> Hash HASH EraIndependentEbReferences
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
UnsafeHash (Int -> Word8 -> ShortByteString
SBS.replicate Int
32 Word8
1))
unknownPoint :: LeiosPoint
unknownPoint :: LeiosPoint
unknownPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint SlotNo
1 (ShortByteString -> Hash HASH EraIndependentEbReferences
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
UnsafeHash (Int -> Word8 -> ShortByteString
SBS.replicate Int
32 Word8
2))
heldTxHash :: Int -> TxHash
heldTxHash :: Int -> TxHash
heldTxHash Int
i = ShortByteString -> TxHash
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
UnsafeHash (Int -> Word8 -> ShortByteString
SBS.replicate Int
31 Word8
0 ShortByteString -> ShortByteString -> ShortByteString
forall a. Semigroup a => a -> a -> a
<> Word8 -> ShortByteString
SBS.singleton (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i))
heldTxBytes :: Int -> BS.ByteString
heldTxBytes :: Int -> ByteString
heldTxBytes Int
i = Int -> Word8 -> ByteString
BS.replicate (Int
10 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i) (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i)
heldTx :: Int -> LeiosTx
heldTx :: Int -> LeiosTx
heldTx = ByteString -> LeiosTx
MkLeiosTx (ByteString -> LeiosTx) -> (Int -> ByteString) -> Int -> LeiosTx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ByteString
heldTxBytes
heldOffsets :: [Int]
heldOffsets :: [Int]
heldOffsets = [Int
0 .. Int
68]
nonCanonicalReferences :: [(TxHash, Word32)]
nonCanonicalReferences :: [(TxHash, Word32)]
nonCanonicalReferences = [(Int -> TxHash
heldTxHash Int
i, Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length (Int -> ByteString
heldTxBytes Int
i))) | Int
i <- [Int
0 .. Int
2]]
nonCanonicalBytes :: Serialised EndorserBlock
nonCanonicalBytes :: Serialised EndorserBlock
nonCanonicalBytes =
ByteString -> Serialised EndorserBlock
forall {k} (a :: k). ByteString -> Serialised a
Serialised (ByteString -> Serialised EndorserBlock)
-> (Encoding -> ByteString) -> Encoding -> Serialised EndorserBlock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Encoding -> ByteString
CBOR.toLazyByteString (Encoding -> Serialised EndorserBlock)
-> Encoding -> Serialised EndorserBlock
forall a b. (a -> b) -> a -> b
$
Encoding
CBOR.encodeMapLenIndef
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ((TxHash, Word32) -> Encoding) -> [(TxHash, Word32)] -> Encoding
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap
(\(TxHash
txHash, Word32
size) -> ByteString -> Encoding
CBOR.encodeBytes (TxHash -> ByteString
forall h a. Hash h a -> ByteString
hashToBytes TxHash
txHash) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word32 -> Encoding
CBOR.encodeWord32 Word32
size)
[(TxHash, Word32)]
nonCanonicalReferences
Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding
CBOR.encodeBreak
nonCanonicalPoint :: LeiosPoint
nonCanonicalPoint :: LeiosPoint
nonCanonicalPoint = SlotNo -> Hash HASH EraIndependentEbReferences -> LeiosPoint
MkLeiosPoint SlotNo
2 (ShortByteString -> Hash HASH EraIndependentEbReferences
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
UnsafeHash (Int -> Word8 -> ShortByteString
SBS.replicate Int
32 Word8
3))
holdHeldEb :: NodeUnderTest (IOSim s) -> IOSim s ()
holdHeldEb :: forall s. NodeUnderTest (IOSim s) -> IOSim s ()
holdHeldEb NodeUnderTest (IOSim s)
node = LeiosDbHandle (IOSim s)
-> (LeiosDbWriter (IOSim s) -> IOSim s ()) -> IOSim s ()
forall (m :: * -> *) a.
MonadThrow m =>
LeiosDbHandle m -> (LeiosDbWriter m -> m a) -> m a
withWriter (NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
-> LeiosDbHandle (IOSim s)
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk -> LeiosDbHandle m
getLeiosDB (NodeUnderTest (IOSim s)
-> NodeKernel (IOSim s) PeerAddr (ConnectionId ()) LeiosTestBlock
forall (m :: * -> *).
NodeUnderTest m
-> NodeKernel m PeerAddr (ConnectionId ()) LeiosTestBlock
nodeKernel NodeUnderTest (IOSim s)
node)) ((LeiosDbWriter (IOSim s) -> IOSim s ()) -> IOSim s ())
-> (LeiosDbWriter (IOSim s) -> IOSim s ()) -> IOSim s ()
forall a b. (a -> b) -> a -> b
$ \LeiosDbWriter (IOSim s)
writer -> do
_ <- Promise (IOSim s) (Set Int) -> IOSim s (Set Int)
forall (m :: * -> *) a. Promise m a -> m a
await (Promise (IOSim s) (Set Int) -> IOSim s (Set Int))
-> IOSim s (Promise (IOSim s) (Set Int)) -> IOSim s (Set Int)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< LeiosDbWriter (IOSim s)
-> HasCallStack =>
LeiosPoint
-> EndorserBlock
-> Map Int TxLocation
-> IOSim s (Promise (IOSim s) (Set Int))
forall (m :: * -> *).
LeiosDbWriter m
-> HasCallStack =>
LeiosPoint
-> EndorserBlock -> Map Int TxLocation -> m (Promise m (Set Int))
writeEbBody LeiosDbWriter (IOSim s)
writer LeiosPoint
heldPoint EndorserBlock
heldEb Map Int TxLocation
forall a. Monoid a => a
mempty
_ <- await =<< writeTxs writer heldPoint (Map.fromList [(i, heldTxBytes i) | i <- heldOffsets])
nonCanonicalEb <-
either (throwIO . userError . show) pure $
deserialiseEndorserBlock (Proxy @DijkstraEra) nonCanonicalBytes
_ <- await =<< writeEbBody writer nonCanonicalPoint nonCanonicalEb mempty
pure ()
nodeRunsLeiosFetch :: NodeToNodeVersion -> IOSim s (Bool, Bool)
nodeRunsLeiosFetch :: forall s. NodeToNodeVersion -> IOSim s (Bool, Bool)
nodeRunsLeiosFetch NodeToNodeVersion
ntnVersion = (NodeUnderTest (IOSim s) -> IOSim s (Bool, Bool))
-> IOSim s (Bool, Bool)
forall s a. (NodeUnderTest (IOSim s) -> IOSim s a) -> IOSim s a
withNode ((NodeUnderTest (IOSim s) -> IOSim s (Bool, Bool))
-> IOSim s (Bool, Bool))
-> (NodeUnderTest (IOSim s) -> IOSim s (Bool, Bool))
-> IOSim s (Bool, Bool)
forall a b. (a -> b) -> a -> b
$ \NodeUnderTest (IOSim s)
node ->
(Bool, Bool) -> IOSim s (Bool, Bool)
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
( TemperatureBundle
[MiniProtocol
'InitiatorMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
Void]
-> Bool
forall {mode :: Mode} {initiatorCtx} {responderCtx} {bytes}
{m :: * -> *} {a} {b}.
TemperatureBundle
[MiniProtocol mode initiatorCtx responderCtx bytes m a b]
-> Bool
runsLeiosFetch (TemperatureBundle
[MiniProtocol
'InitiatorMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
Void]
-> Bool)
-> TemperatureBundle
[MiniProtocol
'InitiatorMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
Void]
-> Bool
forall a b. (a -> b) -> a -> b
$
Set CardanoFeatureFlag
-> MiniProtocolParameters
-> NodeToNodeVersion
-> NodeToNodeVersionData
-> Apps
(IOSim s)
PeerAddr
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
NodeToNodeInitiatorResult
()
-> TemperatureBundle
[MiniProtocol
'InitiatorMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
Void]
forall (m :: * -> *) addr b a c.
Set CardanoFeatureFlag
-> MiniProtocolParameters
-> NodeToNodeVersion
-> NodeToNodeVersionData
-> Apps m addr b b b b b b b b b a c
-> OuroborosBundleWithExpandedCtx
'InitiatorMode addr PeerTrustable b m a Void
NTN.initiator Set CardanoFeatureFlag
forall a. Monoid a => a
mempty MiniProtocolParameters
defaultMiniProtocolParameters NodeToNodeVersion
ntnVersion NodeToNodeVersionData
versionData (NodeUnderTest (IOSim s)
-> BlockNodeToNodeVersion LeiosTestBlock
-> Apps
(IOSim s)
PeerAddr
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
NodeToNodeInitiatorResult
()
forall (m :: * -> *).
NodeUnderTest m
-> BlockNodeToNodeVersion LeiosTestBlock -> NodeApps m
nodeApps NodeUnderTest (IOSim s)
node ())
, TemperatureBundle
[MiniProtocol
'InitiatorResponderMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
()]
-> Bool
forall {mode :: Mode} {initiatorCtx} {responderCtx} {bytes}
{m :: * -> *} {a} {b}.
TemperatureBundle
[MiniProtocol mode initiatorCtx responderCtx bytes m a b]
-> Bool
runsLeiosFetch (TemperatureBundle
[MiniProtocol
'InitiatorResponderMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
()]
-> Bool)
-> TemperatureBundle
[MiniProtocol
'InitiatorResponderMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
()]
-> Bool
forall a b. (a -> b) -> a -> b
$
Set CardanoFeatureFlag
-> MiniProtocolParameters
-> NodeToNodeVersion
-> NodeToNodeVersionData
-> Apps
(IOSim s)
PeerAddr
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
NodeToNodeInitiatorResult
()
-> TemperatureBundle
[MiniProtocol
'InitiatorResponderMode
(ExpandedInitiatorContext PeerAddr PeerTrustable (IOSim s))
(ResponderContext PeerAddr)
ByteString
(IOSim s)
NodeToNodeInitiatorResult
()]
forall (m :: * -> *) addr b a c.
Set CardanoFeatureFlag
-> MiniProtocolParameters
-> NodeToNodeVersion
-> NodeToNodeVersionData
-> Apps m addr b b b b b b b b b a c
-> OuroborosBundleWithExpandedCtx
'InitiatorResponderMode addr PeerTrustable b m a c
NTN.initiatorAndResponder
Set CardanoFeatureFlag
forall a. Monoid a => a
mempty
MiniProtocolParameters
defaultMiniProtocolParameters
NodeToNodeVersion
ntnVersion
NodeToNodeVersionData
versionData
(NodeUnderTest (IOSim s)
-> BlockNodeToNodeVersion LeiosTestBlock
-> Apps
(IOSim s)
PeerAddr
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
NodeToNodeInitiatorResult
()
forall (m :: * -> *).
NodeUnderTest m
-> BlockNodeToNodeVersion LeiosTestBlock -> NodeApps m
nodeApps NodeUnderTest (IOSim s)
node ())
)
where
versionData :: NodeToNodeVersionData
versionData = NodeToNodeVersion -> NodeToNodeVersionData
nodeVersionData NodeToNodeVersion
ntnVersion
runsLeiosFetch :: TemperatureBundle
[MiniProtocol mode initiatorCtx responderCtx bytes m a b]
-> Bool
runsLeiosFetch TemperatureBundle
[MiniProtocol mode initiatorCtx responderCtx bytes m a b]
bundle = case TemperatureBundle
[MiniProtocol mode initiatorCtx responderCtx bytes m a b]
-> WithProtocolTemperature
'Hot [MiniProtocol mode initiatorCtx responderCtx bytes m a b]
forall a. TemperatureBundle a -> WithProtocolTemperature 'Hot a
withHot TemperatureBundle
[MiniProtocol mode initiatorCtx responderCtx bytes m a b]
bundle of
WithHot [MiniProtocol mode initiatorCtx responderCtx bytes m a b]
protocols -> MiniProtocolNum
leiosFetchMiniProtocolNum MiniProtocolNum -> [MiniProtocolNum] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (MiniProtocol mode initiatorCtx responderCtx bytes m a b
-> MiniProtocolNum)
-> [MiniProtocol mode initiatorCtx responderCtx bytes m a b]
-> [MiniProtocolNum]
forall a b. (a -> b) -> [a] -> [b]
map MiniProtocol mode initiatorCtx responderCtx bytes m a b
-> MiniProtocolNum
forall (mode :: Mode) initiatorCtx responderCtx bytes (m :: * -> *)
a b.
MiniProtocol mode initiatorCtx responderCtx bytes m a b
-> MiniProtocolNum
miniProtocolNum [MiniProtocol mode initiatorCtx responderCtx bytes m a b]
protocols
nodeLeiosFetchServer ::
NodeVsEnvConnection (IOSim s) -> IOSim s (STM (IOSim s) (Either SomeException ()))
nodeLeiosFetchServer :: forall s.
NodeVsEnvConnection (IOSim s)
-> IOSim s (STM (IOSim s) (Either SomeException ()))
nodeLeiosFetchServer NodeVsEnvConnection (IOSim s)
conn =
IOSim s (STM (IOSim s) (Either SomeException ()))
-> (STM s (Either SomeException ())
-> IOSim s (STM (IOSim s) (Either SomeException ())))
-> Maybe (STM s (Either SomeException ()))
-> IOSim s (STM (IOSim s) (Either SomeException ()))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (IOError -> IOSim s (STM (IOSim s) (Either SomeException ()))
forall e a. Exception e => e -> IOSim s a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO (IOError -> IOSim s (STM (IOSim s) (Either SomeException ())))
-> IOError -> IOSim s (STM (IOSim s) (Either SomeException ()))
forall a b. (a -> b) -> a -> b
$ [Char] -> IOError
userError [Char]
"the node does not run a LeiosFetch server") STM s (Either SomeException ())
-> IOSim s (STM (IOSim s) (Either SomeException ()))
STM s (Either SomeException ())
-> IOSim s (STM s (Either SomeException ()))
forall a. a -> IOSim s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (STM s (Either SomeException ()))
-> IOSim s (STM (IOSim s) (Either SomeException ())))
-> Maybe (STM s (Either SomeException ()))
-> IOSim s (STM (IOSim s) (Either SomeException ()))
forall a b. (a -> b) -> a -> b
$
MiniProtocolNum
-> Map MiniProtocolNum (STM s (Either SomeException ()))
-> Maybe (STM s (Either SomeException ()))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup MiniProtocolNum
leiosFetchMiniProtocolNum (NodeVsEnvConnection (IOSim s)
-> Map MiniProtocolNum (STM (IOSim s) (Either SomeException ()))
forall (m :: * -> *).
NodeVsEnvConnection m
-> Map MiniProtocolNum (STM m (Either SomeException ()))
connNodeResponders NodeVsEnvConnection (IOSim s)
conn)