{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Test.ThreadNet.Network (
CalcMessageDelay (..)
, ForgeEbbEnv (..)
, RekeyM
, TestNodeInitialization (..)
, ThreadNetworkArgs (..)
, TracingConstraints
, noCalcMessageDelay
, plainTestNodeInitialization
, runThreadNetwork
, MiniProtocolFatalException (..)
, MiniProtocolState (..)
, NodeDBs (..)
, NodeOutput (..)
, TestOutput (..)
) where
import Cardano.Network.PeerSelection.Bootstrap
(UseBootstrapPeers (..))
import Codec.CBOR.Read (DeserialiseFailure)
import qualified Control.Concurrent.Class.MonadSTM as MonadSTM
import Control.Concurrent.Class.MonadSTM.Strict (newTMVar)
import qualified Control.Exception as Exn
import Control.Monad
import Control.Monad.Class.MonadTime.SI (MonadTime)
import Control.Monad.Class.MonadTimer.SI (MonadTimer)
import qualified Control.Monad.Except as Exc
import Control.ResourceRegistry
import Control.Tracer
import qualified Data.ByteString.Lazy as Lazy
import Data.Functor.Contravariant ((>$<))
import Data.Functor.Identity (Identity)
import qualified Data.List as List
import qualified Data.List.NonEmpty as NE
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Typeable as Typeable
import Data.Void (Void)
import GHC.Stack
import Network.TypedProtocol.Codec (AnyMessage (..), CodecFailure,
mapFailureCodec)
import qualified Network.TypedProtocol.Codec as Codec
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.BlockchainTime
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.Inspect
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Ledger.Tables.Utils
import Ouroboros.Consensus.Mempool
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client as CSClient
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.HistoricityCheck as HistoricityCheck
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck as InFutureCheck
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
import Ouroboros.Consensus.Node.ExitPolicy
import Ouroboros.Consensus.Node.Genesis
import qualified Ouroboros.Consensus.Node.GSM as GSM
import Ouroboros.Consensus.Node.InitStorage
import Ouroboros.Consensus.Node.NetworkProtocolVersion
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
import Ouroboros.Consensus.Node.Tracers
import Ouroboros.Consensus.NodeId
import Ouroboros.Consensus.NodeKernel as NodeKernel
import Ouroboros.Consensus.Protocol.Abstract
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
import qualified Ouroboros.Consensus.Storage.ChainDB.API.Types.InvalidBlockPunishment as InvalidBlockPunishment
import Ouroboros.Consensus.Storage.ChainDB.Impl.Args
import Ouroboros.Consensus.Storage.ChainDB.Impl.Types
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
import Ouroboros.Consensus.Storage.LedgerDB
import Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB
import Ouroboros.Consensus.Util.Assert
import Ouroboros.Consensus.Util.Condense
import Ouroboros.Consensus.Util.Enclose (pattern FallingEdge)
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Consensus.Util.Orphans ()
import Ouroboros.Consensus.Util.RedundantConstraints
import Ouroboros.Consensus.Util.STM
import Ouroboros.Consensus.Util.Time
import qualified Ouroboros.Network.AnchoredFragment as AF
import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..),
TraceLabelPeer (..))
import Ouroboros.Network.Channel
import Ouroboros.Network.ControlMessage (ControlMessage (..))
import Ouroboros.Network.Mock.Chain (Chain (Genesis))
import Ouroboros.Network.NodeToNode (ConnectionId (..),
ExpandedInitiatorContext (..), IsBigLedgerPeer (..),
MiniProtocolParameters (..), ResponderContext (..))
import Ouroboros.Network.PeerSelection.Governor
(makePublicPeerSelectionStateVar)
import Ouroboros.Network.PeerSelection.PeerMetric (nullMetric)
import Ouroboros.Network.Point (WithOrigin (..))
import qualified Ouroboros.Network.Protocol.ChainSync.Type as CS
import Ouroboros.Network.Protocol.KeepAlive.Type
import Ouroboros.Network.Protocol.Limits (waitForever)
import Ouroboros.Network.Protocol.LocalStateQuery.Type
import Ouroboros.Network.Protocol.PeerSharing.Type (PeerSharing)
import Ouroboros.Network.Protocol.TxSubmission2.Type
import qualified System.FS.Sim.MockFS as Mock
import System.FS.Sim.MockFS (MockFS)
import System.Random (mkStdGen, split)
import Test.ThreadNet.TxGen
import Test.ThreadNet.Util.NodeJoinPlan
import Test.ThreadNet.Util.NodeRestarts
import Test.ThreadNet.Util.NodeTopology
import Test.ThreadNet.Util.Seed
import Test.Util.ChainDB
import qualified Test.Util.HardFork.Future as HFF
import Test.Util.HardFork.Future (Future)
import qualified Test.Util.HardFork.OracularClock as OracularClock
import Test.Util.HardFork.OracularClock (OracularClock (..))
import Test.Util.Slots (NumSlots (..))
import Test.Util.Time
import Test.Util.Tracer
data ForgeEbbEnv blk = ForgeEbbEnv
{ forall blk.
ForgeEbbEnv blk
-> TopLevelConfig blk -> SlotNo -> BlockNo -> ChainHash blk -> blk
forgeEBB ::
TopLevelConfig blk
-> SlotNo
-> BlockNo
-> ChainHash blk
-> blk
}
instance Show (ForgeEbbEnv blk) where
showsPrec :: Int -> ForgeEbbEnv blk -> ShowS
showsPrec Int
p ForgeEbbEnv blk
_ = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ForgeEbbEnv _"
type RekeyM m blk =
CoreNodeId
-> ProtocolInfo blk
-> m [BlockForging m blk]
-> SlotNo
-> (SlotNo -> m EpochNo)
-> m (TestNodeInitialization m blk)
data TestNodeInitialization m blk = TestNodeInitialization
{ forall (m :: * -> *) blk.
TestNodeInitialization m blk -> [GenTx blk]
tniCrucialTxs :: [GenTx blk]
, forall (m :: * -> *) blk.
TestNodeInitialization m blk -> ProtocolInfo blk
tniProtocolInfo :: ProtocolInfo blk
, forall (m :: * -> *) blk.
TestNodeInitialization m blk -> m [BlockForging m blk]
tniBlockForging :: m [BlockForging m blk]
}
plainTestNodeInitialization ::
ProtocolInfo blk
-> m [BlockForging m blk]
-> TestNodeInitialization m blk
plainTestNodeInitialization :: forall blk (m :: * -> *).
ProtocolInfo blk
-> m [BlockForging m blk] -> TestNodeInitialization m blk
plainTestNodeInitialization ProtocolInfo blk
pInfo m [BlockForging m blk]
blockForging = TestNodeInitialization
{ tniCrucialTxs :: [GenTx blk]
tniCrucialTxs = []
, tniProtocolInfo :: ProtocolInfo blk
tniProtocolInfo = ProtocolInfo blk
pInfo
, tniBlockForging :: m [BlockForging m blk]
tniBlockForging = m [BlockForging m blk]
blockForging
}
newtype CalcMessageDelay blk = CalcMessageDelay
((CoreNodeId, CoreNodeId) -> SlotNo -> Header blk -> NumSlots)
noCalcMessageDelay :: CalcMessageDelay blk
noCalcMessageDelay :: forall blk. CalcMessageDelay blk
noCalcMessageDelay = ((CoreNodeId, CoreNodeId) -> SlotNo -> Header blk -> NumSlots)
-> CalcMessageDelay blk
forall blk.
((CoreNodeId, CoreNodeId) -> SlotNo -> Header blk -> NumSlots)
-> CalcMessageDelay blk
CalcMessageDelay (((CoreNodeId, CoreNodeId) -> SlotNo -> Header blk -> NumSlots)
-> CalcMessageDelay blk)
-> ((CoreNodeId, CoreNodeId) -> SlotNo -> Header blk -> NumSlots)
-> CalcMessageDelay blk
forall a b. (a -> b) -> a -> b
$ \(CoreNodeId, CoreNodeId)
_ SlotNo
_ Header blk
_ -> Word64 -> NumSlots
NumSlots Word64
0
instance Show (CalcMessageDelay blk) where
show :: CalcMessageDelay blk -> String
show CalcMessageDelay blk
_ = String
"_CalcMessageDelay"
data ThreadNetworkArgs m blk = ThreadNetworkArgs
{ forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> Maybe (ForgeEbbEnv blk)
tnaForgeEbbEnv :: Maybe (ForgeEbbEnv blk)
, forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> Future
tnaFuture :: Future
, forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NodeJoinPlan
tnaJoinPlan :: NodeJoinPlan
, forall (m :: * -> *) blk.
ThreadNetworkArgs m blk
-> CoreNodeId -> TestNodeInitialization m blk
tnaNodeInfo :: CoreNodeId -> TestNodeInitialization m blk
, forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NumCoreNodes
tnaNumCoreNodes :: NumCoreNodes
, forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NumSlots
tnaNumSlots :: NumSlots
, forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> CalcMessageDelay blk
tnaMessageDelay :: CalcMessageDelay blk
, forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> Seed
tnaSeed :: Seed
, forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> Maybe (m (RekeyM m blk))
tnaMkRekeyM :: Maybe (m (RekeyM m blk))
, forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NodeRestarts
tnaRestarts :: NodeRestarts
, forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NodeTopology
tnaTopology :: NodeTopology
, :: TxGenExtra blk
, forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> NodeToNodeVersion
tnaVersion :: NodeToNodeVersion
, forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> BlockNodeToNodeVersion blk
tnaBlockVersion :: BlockNodeToNodeVersion blk
}
data VertexStatus m blk
= VDown (Chain blk) (LedgerState blk EmptyMK)
| VFalling
| VUp !(NodeKernel m NodeId Void blk) !(LimitedApp m NodeId blk)
data EdgeStatus
= EDown
| EUp
deriving (EdgeStatus -> EdgeStatus -> Bool
(EdgeStatus -> EdgeStatus -> Bool)
-> (EdgeStatus -> EdgeStatus -> Bool) -> Eq EdgeStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EdgeStatus -> EdgeStatus -> Bool
== :: EdgeStatus -> EdgeStatus -> Bool
$c/= :: EdgeStatus -> EdgeStatus -> Bool
/= :: EdgeStatus -> EdgeStatus -> Bool
Eq)
type VertexStatusVar m blk = StrictTVar m (VertexStatus m blk)
type EdgeStatusVar m = StrictTVar m EdgeStatus
runThreadNetwork :: forall m blk.
( IOLike m
, MonadTime m
, MonadTimer m
, RunNode blk
, TxGen blk
, TracingConstraints blk
, HasCallStack
)
=> SystemTime m -> ThreadNetworkArgs m blk -> m (TestOutput blk)
runThreadNetwork :: forall (m :: * -> *) blk.
(IOLike m, MonadTime m, MonadTimer m, RunNode blk, TxGen blk,
TracingConstraints blk, HasCallStack) =>
SystemTime m -> ThreadNetworkArgs m blk -> m (TestOutput blk)
runThreadNetwork SystemTime m
systemTime ThreadNetworkArgs
{ tnaForgeEbbEnv :: forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> Maybe (ForgeEbbEnv blk)
tnaForgeEbbEnv = Maybe (ForgeEbbEnv blk)
mbForgeEbbEnv
, tnaFuture :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> Future
tnaFuture = Future
future
, tnaJoinPlan :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NodeJoinPlan
tnaJoinPlan = NodeJoinPlan
nodeJoinPlan
, tnaNodeInfo :: forall (m :: * -> *) blk.
ThreadNetworkArgs m blk
-> CoreNodeId -> TestNodeInitialization m blk
tnaNodeInfo = CoreNodeId -> TestNodeInitialization m blk
mkProtocolInfo
, tnaNumCoreNodes :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NumCoreNodes
tnaNumCoreNodes = NumCoreNodes
numCoreNodes
, tnaNumSlots :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NumSlots
tnaNumSlots = NumSlots
numSlots
, tnaMessageDelay :: forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> CalcMessageDelay blk
tnaMessageDelay = CalcMessageDelay blk
calcMessageDelay
, tnaSeed :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> Seed
tnaSeed = Seed
seed
, tnaMkRekeyM :: forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> Maybe (m (RekeyM m blk))
tnaMkRekeyM = Maybe (m (RekeyM m blk))
mbMkRekeyM
, tnaRestarts :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NodeRestarts
tnaRestarts = NodeRestarts
nodeRestarts
, tnaTopology :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> NodeTopology
tnaTopology = NodeTopology
nodeTopology
, tnaTxGenExtra :: forall (m :: * -> *) blk. ThreadNetworkArgs m blk -> TxGenExtra blk
tnaTxGenExtra = TxGenExtra blk
txGenExtra
, tnaVersion :: forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> NodeToNodeVersion
tnaVersion = NodeToNodeVersion
version
, tnaBlockVersion :: forall (m :: * -> *) blk.
ThreadNetworkArgs m blk -> BlockNodeToNodeVersion blk
tnaBlockVersion = BlockNodeToNodeVersion blk
blockVersion
} = (ResourceRegistry m -> m (TestOutput blk)) -> m (TestOutput blk)
forall (m :: * -> *) a.
(MonadSTM m, MonadMask m, MonadThread m, HasCallStack) =>
(ResourceRegistry m -> m a) -> m a
withRegistry ((ResourceRegistry m -> m (TestOutput blk)) -> m (TestOutput blk))
-> (ResourceRegistry m -> m (TestOutput blk)) -> m (TestOutput blk)
forall a b. (a -> b) -> a -> b
$ \ResourceRegistry m
sharedRegistry -> do
mbRekeyM <- Maybe (m (RekeyM m blk)) -> m (Maybe (RekeyM m blk))
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => Maybe (m a) -> m (Maybe a)
sequence Maybe (m (RekeyM m blk))
mbMkRekeyM
let clock = SystemTime m -> NumSlots -> Future -> OracularClock m
forall (m :: * -> *).
IOLike m =>
SystemTime m -> NumSlots -> Future -> OracularClock m
OracularClock.mkOracularClock SystemTime m
systemTime NumSlots
numSlots Future
future
vertexStatusVars <- fmap Map.fromList $ do
forM coreNodeIds $ \CoreNodeId
nid -> do
let nodeInitData :: TestNodeInitialization m blk
nodeInitData = CoreNodeId -> TestNodeInitialization m blk
mkProtocolInfo (Word64 -> CoreNodeId
CoreNodeId Word64
0)
TestNodeInitialization{ProtocolInfo blk
tniProtocolInfo :: forall (m :: * -> *) blk.
TestNodeInitialization m blk -> ProtocolInfo blk
tniProtocolInfo :: ProtocolInfo blk
tniProtocolInfo} = TestNodeInitialization m blk
nodeInitData
ProtocolInfo{ExtLedgerState blk ValuesMK
pInfoInitLedger :: ExtLedgerState blk ValuesMK
pInfoInitLedger :: forall b. ProtocolInfo b -> ExtLedgerState b ValuesMK
pInfoInitLedger} = ProtocolInfo blk
tniProtocolInfo
ExtLedgerState{LedgerState blk ValuesMK
ledgerState :: LedgerState blk ValuesMK
ledgerState :: forall blk (mk :: MapKind).
ExtLedgerState blk mk -> LedgerState blk mk
ledgerState} = ExtLedgerState blk ValuesMK
pInfoInitLedger
v <-
VertexStatus m blk -> m (StrictTVar m (VertexStatus m blk))
forall (m :: * -> *) a. MonadSTM m => a -> m (StrictTVar m a)
uncheckedNewTVarM
(VertexStatus m blk -> m (StrictTVar m (VertexStatus m blk)))
-> VertexStatus m blk -> m (StrictTVar m (VertexStatus m blk))
forall a b. (a -> b) -> a -> b
$ Chain blk -> LedgerState blk EmptyMK -> VertexStatus m blk
forall (m :: * -> *) blk.
Chain blk -> LedgerState blk EmptyMK -> VertexStatus m blk
VDown Chain blk
forall block. Chain block
Genesis
(LedgerState blk EmptyMK -> VertexStatus m blk)
-> LedgerState blk EmptyMK -> VertexStatus m blk
forall a b. (a -> b) -> a -> b
$ LedgerState blk ValuesMK -> LedgerState blk EmptyMK
forall (l :: LedgerStateKind) (mk :: MapKind).
HasLedgerTables l =>
l mk -> l EmptyMK
forgetLedgerTables LedgerState blk ValuesMK
ledgerState
pure (nid, v)
let uedges = NodeTopology -> [(CoreNodeId, CoreNodeId)]
edgesNodeTopology NodeTopology
nodeTopology
edgeStatusVars <- fmap (Map.fromList . concat) $ do
let nodeInitData = CoreNodeId -> TestNodeInitialization m blk
mkProtocolInfo (Word64 -> CoreNodeId
CoreNodeId Word64
0)
TestNodeInitialization{tniProtocolInfo} = nodeInitData
ProtocolInfo{pInfoConfig} = tniProtocolInfo
codecConfig = TopLevelConfig blk -> CodecConfig blk
forall blk. TopLevelConfig blk -> CodecConfig blk
configCodec TopLevelConfig blk
pInfoConfig
forM uedges $ \(CoreNodeId, CoreNodeId)
uedge -> do
ResourceRegistry m
-> OracularClock m
-> Tracer m (SlotNo, MiniProtocolState)
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> Map CoreNodeId (StrictTVar m (VertexStatus m blk))
-> (CoreNodeId, CoreNodeId)
-> m [((CoreNodeId, CoreNodeId), EdgeStatusVar m)]
forall (m :: * -> *) blk.
(IOLike m, RunNode blk, HasCallStack) =>
ResourceRegistry m
-> OracularClock m
-> Tracer m (SlotNo, MiniProtocolState)
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> Map CoreNodeId (VertexStatusVar m blk)
-> (CoreNodeId, CoreNodeId)
-> m [((CoreNodeId, CoreNodeId), EdgeStatusVar m)]
forkBothEdges
ResourceRegistry m
sharedRegistry
OracularClock m
clock
Tracer m (SlotNo, MiniProtocolState)
forall (m :: * -> *) a. (Applicative m, Show a) => Tracer m a
nullDebugTracer
(NodeToNodeVersion
version, BlockNodeToNodeVersion blk
blockVersion)
(CodecConfig blk
codecConfig, CalcMessageDelay blk
calcMessageDelay)
Map CoreNodeId (StrictTVar m (VertexStatus m blk))
vertexStatusVars
(CoreNodeId, CoreNodeId)
uedge
let nodesByJoinSlot =
((SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))
-> SlotNo)
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))]
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))]
forall b a. Ord b => (a -> b) -> [a] -> [a]
List.sortOn (SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk))) -> SlotNo
forall a b. (a, b) -> a
fst ([(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))]
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))])
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))]
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))]
forall a b. (a -> b) -> a -> b
$
((CoreNodeId, StrictTVar m (VertexStatus m blk))
-> (SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk))))
-> [(CoreNodeId, StrictTVar m (VertexStatus m blk))]
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))]
forall a b. (a -> b) -> [a] -> [b]
map (\nv :: (CoreNodeId, StrictTVar m (VertexStatus m blk))
nv@(CoreNodeId
n, StrictTVar m (VertexStatus m blk)
_) -> (CoreNodeId -> SlotNo
joinSlotOf CoreNodeId
n, (CoreNodeId, StrictTVar m (VertexStatus m blk))
nv)) ([(CoreNodeId, StrictTVar m (VertexStatus m blk))]
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))])
-> [(CoreNodeId, StrictTVar m (VertexStatus m blk))]
-> [(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))]
forall a b. (a -> b) -> a -> b
$
Map CoreNodeId (StrictTVar m (VertexStatus m blk))
-> [(CoreNodeId, StrictTVar m (VertexStatus m blk))]
forall k a. Map k a -> [(k, a)]
Map.toList Map CoreNodeId (StrictTVar m (VertexStatus m blk))
vertexStatusVars
vertexInfos0 <- forM nodesByJoinSlot $ \(SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))
vertexData -> do
let (SlotNo
joinSlot, (CoreNodeId
coreNodeId, StrictTVar m (VertexStatus m blk)
vertexStatusVar)) = (SlotNo, (CoreNodeId, StrictTVar m (VertexStatus m blk)))
vertexData
tooLate <- OracularClock m -> SlotNo -> m Bool
forall (m :: * -> *). OracularClock m -> SlotNo -> m Bool
OracularClock.blockUntilSlot OracularClock m
clock SlotNo
joinSlot
when tooLate $ do
error $ "unsatisfiable nodeJoinPlan: " ++ show coreNodeId
(nodeInfo, readNodeInfo) <- newNodeInfo
nextInstrSlotVar <- uncheckedNewTVarM joinSlot
let myEdgeStatusVars =
[ EdgeStatusVar m
v
| ((CoreNodeId
n1, CoreNodeId
n2), EdgeStatusVar m
v) <- Map (CoreNodeId, CoreNodeId) (EdgeStatusVar m)
-> [((CoreNodeId, CoreNodeId), EdgeStatusVar m)]
forall k a. Map k a -> [(k, a)]
Map.toList Map (CoreNodeId, CoreNodeId) (EdgeStatusVar m)
edgeStatusVars
, CoreNodeId
coreNodeId CoreNodeId -> [CoreNodeId] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CoreNodeId
n1, CoreNodeId
n2]
]
forkVertex
mbRekeyM
clock
joinSlot
sharedRegistry
coreNodeId
vertexStatusVar
myEdgeStatusVars
nodeInfo
nextInstrSlotVar
forkInstrumentation
clock
sharedRegistry
vertexStatusVar
nodeInfo
nextInstrSlotVar
return (coreNodeId, vertexStatusVar, readNodeInfo)
OracularClock.waitUntilDone clock
vertexInfos <-
atomically $
forM vertexInfos0 $ \(CoreNodeId
coreNodeId, StrictTVar m (VertexStatus m blk)
vertexStatusVar, m (NodeInfo blk MockFS [])
readNodeInfo) -> do
StrictTVar m (VertexStatus m blk) -> STM m (VertexStatus m blk)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m (VertexStatus m blk)
vertexStatusVar STM m (VertexStatus m blk)
-> (VertexStatus m blk
-> STM
m
(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK))
-> STM
m
(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)
forall a b. STM m a -> (a -> STM m b) -> STM m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
VDown Chain blk
ch LedgerState blk EmptyMK
ldgr -> (CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)
-> STM
m
(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)
forall a. a -> STM m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CoreNodeId
coreNodeId, m (NodeInfo blk MockFS [])
readNodeInfo, Chain blk
ch, LedgerState blk EmptyMK
ldgr)
VertexStatus m blk
_ -> STM
m
(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)
forall a. STM m a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
mkTestOutput vertexInfos
where
()
_ = Proxy (Show (LedgerView (BlockProtocol blk))) -> ()
forall (c :: Constraint) (proxy :: Constraint -> *).
c =>
proxy c -> ()
keepRedundantConstraint (forall {k} (t :: k). Proxy t
forall (t :: Constraint). Proxy t
Proxy @(Show (LedgerView (BlockProtocol blk))))
epochSize0 :: EpochSize
epochSize0 :: EpochSize
epochSize0 = Future -> EpochSize
HFF.futureFirstEpochSize Future
future
coreNodeIds :: [CoreNodeId]
coreNodeIds :: [CoreNodeId]
coreNodeIds = NumCoreNodes -> [CoreNodeId]
enumCoreNodes NumCoreNodes
numCoreNodes
joinSlotOf :: CoreNodeId -> SlotNo
joinSlotOf :: CoreNodeId -> SlotNo
joinSlotOf = HasCallStack => NodeJoinPlan -> CoreNodeId -> SlotNo
NodeJoinPlan -> CoreNodeId -> SlotNo
coreNodeIdJoinSlot NodeJoinPlan
nodeJoinPlan
forkVertex
:: Maybe (RekeyM m blk)
-> OracularClock m
-> SlotNo
-> ResourceRegistry m
-> CoreNodeId
-> VertexStatusVar m blk
-> [EdgeStatusVar m]
-> NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
-> StrictTVar m SlotNo
-> m ()
forkVertex :: Maybe (RekeyM m blk)
-> OracularClock m
-> SlotNo
-> ResourceRegistry m
-> CoreNodeId
-> StrictTVar m (VertexStatus m blk)
-> [EdgeStatusVar m]
-> NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
-> StrictTVar m SlotNo
-> m ()
forkVertex
Maybe (RekeyM m blk)
mbRekeyM
OracularClock m
clock
SlotNo
joinSlot
ResourceRegistry m
sharedRegistry
CoreNodeId
coreNodeId
StrictTVar m (VertexStatus m blk)
vertexStatusVar
[EdgeStatusVar m]
edgeStatusVars
NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
nodeInfo
StrictTVar m SlotNo
nextInstrSlotVar =
m (Thread m ()) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (Thread m ()) -> m ()) -> m (Thread m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ ResourceRegistry m -> String -> m () -> m (Thread m ())
forall (m :: * -> *) a.
(MonadAsync m, MonadFork m, MonadMask m, HasCallStack) =>
ResourceRegistry m -> String -> m a -> m (Thread m a)
forkLinkedThread ResourceRegistry m
sharedRegistry String
label (m () -> m (Thread m ())) -> m () -> m (Thread m ())
forall a b. (a -> b) -> a -> b
$ do
SlotNo
-> ProtocolInfo blk
-> m [BlockForging m blk]
-> NodeRestart
-> Map SlotNo NodeRestart
-> m ()
loop SlotNo
0 ProtocolInfo blk
tniProtocolInfo m [BlockForging m blk]
tniBlockForging NodeRestart
NodeRestart Map SlotNo NodeRestart
restarts0
where
label :: String
label = String
"vertex-" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> CoreNodeId -> String
forall a. Condense a => a -> String
condense CoreNodeId
coreNodeId
TestNodeInitialization
{ [GenTx blk]
tniCrucialTxs :: forall (m :: * -> *) blk.
TestNodeInitialization m blk -> [GenTx blk]
tniCrucialTxs :: [GenTx blk]
tniCrucialTxs
, ProtocolInfo blk
tniProtocolInfo :: forall (m :: * -> *) blk.
TestNodeInitialization m blk -> ProtocolInfo blk
tniProtocolInfo :: ProtocolInfo blk
tniProtocolInfo
, m [BlockForging m blk]
tniBlockForging :: forall (m :: * -> *) blk.
TestNodeInitialization m blk -> m [BlockForging m blk]
tniBlockForging :: m [BlockForging m blk]
tniBlockForging
} = CoreNodeId -> TestNodeInitialization m blk
mkProtocolInfo CoreNodeId
coreNodeId
restarts0 :: Map SlotNo NodeRestart
restarts0 :: Map SlotNo NodeRestart
restarts0 = (Map CoreNodeId NodeRestart -> Maybe NodeRestart)
-> Map SlotNo (Map CoreNodeId NodeRestart)
-> Map SlotNo NodeRestart
forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe (CoreNodeId -> Map CoreNodeId NodeRestart -> Maybe NodeRestart
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup CoreNodeId
coreNodeId) Map SlotNo (Map CoreNodeId NodeRestart)
m
where
NodeRestarts Map SlotNo (Map CoreNodeId NodeRestart)
m = NodeRestarts
nodeRestarts
loop :: SlotNo
-> ProtocolInfo blk
-> m [BlockForging m blk]
-> NodeRestart
-> Map SlotNo NodeRestart -> m ()
loop :: SlotNo
-> ProtocolInfo blk
-> m [BlockForging m blk]
-> NodeRestart
-> Map SlotNo NodeRestart
-> m ()
loop SlotNo
s ProtocolInfo blk
pInfo m [BlockForging m blk]
blockForging NodeRestart
nr Map SlotNo NodeRestart
rs = do
(again, finalChain, finalLdgr) <- (ResourceRegistry m
-> m (Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart),
Chain blk, LedgerState blk EmptyMK))
-> m (Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart),
Chain blk, LedgerState blk EmptyMK)
forall (m :: * -> *) a.
(MonadSTM m, MonadMask m, MonadThread m, HasCallStack) =>
(ResourceRegistry m -> m a) -> m a
withRegistry ((ResourceRegistry m
-> m (Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart),
Chain blk, LedgerState blk EmptyMK))
-> m (Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart),
Chain blk, LedgerState blk EmptyMK))
-> (ResourceRegistry m
-> m (Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart),
Chain blk, LedgerState blk EmptyMK))
-> m (Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart),
Chain blk, LedgerState blk EmptyMK)
forall a b. (a -> b) -> a -> b
$ \ResourceRegistry m
nodeRegistry -> do
tni' <- case (NodeRestart
nr, Maybe (RekeyM m blk)
mbRekeyM) of
(NodeRestart
NodeRekey, Just RekeyM m blk
rekeyM) -> do
RekeyM m blk
rekeyM CoreNodeId
coreNodeId ProtocolInfo blk
pInfo m [BlockForging m blk]
blockForging SlotNo
s (EpochNo -> m EpochNo
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EpochNo -> m EpochNo)
-> (SlotNo -> EpochNo) -> SlotNo -> m EpochNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Future -> SlotNo -> EpochNo
HFF.futureSlotToEpoch Future
future)
(NodeRestart, Maybe (RekeyM m blk))
_ ->
TestNodeInitialization m blk -> m (TestNodeInitialization m blk)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TestNodeInitialization m blk -> m (TestNodeInitialization m blk))
-> TestNodeInitialization m blk -> m (TestNodeInitialization m blk)
forall a b. (a -> b) -> a -> b
$ ProtocolInfo blk
-> m [BlockForging m blk] -> TestNodeInitialization m blk
forall blk (m :: * -> *).
ProtocolInfo blk
-> m [BlockForging m blk] -> TestNodeInitialization m blk
plainTestNodeInitialization ProtocolInfo blk
pInfo m [BlockForging m blk]
blockForging
let TestNodeInitialization
{ tniCrucialTxs = crucialTxs'
, tniProtocolInfo = pInfo'
, tniBlockForging = blockForging'
} = tni'
(kernel, app) <- forkNode
coreNodeId
clock
joinSlot
nodeRegistry
pInfo'
blockForging'
nodeInfo
(crucialTxs' ++ tniCrucialTxs)
atomically $ writeTVar vertexStatusVar $ VUp kernel app
again <- case Map.minViewWithKey rs of
Maybe ((SlotNo, NodeRestart), Map SlotNo NodeRestart)
Nothing -> do
OracularClock m -> m ()
forall (m :: * -> *). OracularClock m -> m ()
OracularClock.waitUntilDone OracularClock m
clock
Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart)
-> m (Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart))
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart)
forall a. Maybe a
Nothing
Just ((SlotNo
s', NodeRestart
nr'), Map SlotNo NodeRestart
rs') -> do
tooLate <- OracularClock m -> SlotNo -> m Bool
forall (m :: * -> *). OracularClock m -> SlotNo -> m Bool
OracularClock.blockUntilSlot OracularClock m
clock SlotNo
s'
when tooLate $ do
error $ "unsatisfiable nodeRestarts: "
++ show (coreNodeId, s')
atomically $ do
nextSlot <- readTVar nextInstrSlotVar
check $ nextSlot > s'
pure $ Just (s', pInfo', blockForging', nr', rs')
atomically $ writeTVar vertexStatusVar VFalling
forM_ edgeStatusVars $ \EdgeStatusVar m
edgeStatusVar -> STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
EdgeStatusVar m -> STM m EdgeStatus
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar EdgeStatusVar m
edgeStatusVar STM m EdgeStatus -> (EdgeStatus -> STM m ()) -> STM m ()
forall a b. STM m a -> (a -> STM m b) -> STM m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> STM m ()
forall (m :: * -> *). MonadSTM m => Bool -> STM m ()
check (Bool -> STM m ())
-> (EdgeStatus -> Bool) -> EdgeStatus -> STM m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EdgeStatus -> EdgeStatus -> Bool
forall a. Eq a => a -> a -> Bool
== EdgeStatus
EDown)
let chainDB = NodeKernel m NodeId Void blk -> ChainDB m blk
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk -> ChainDB m blk
getChainDB NodeKernel m NodeId Void blk
kernel
ExtLedgerState{ledgerState} <- atomically $
ChainDB.getCurrentLedger chainDB
finalChain <- ChainDB.toChain chainDB
pure (again, finalChain, ledgerState)
atomically $ writeTVar vertexStatusVar $
VDown finalChain finalLdgr
case again of
Maybe
(SlotNo, ProtocolInfo blk, m [BlockForging m blk], NodeRestart,
Map SlotNo NodeRestart)
Nothing -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Just (SlotNo
s', ProtocolInfo blk
pInfo', m [BlockForging m blk]
blockForging', NodeRestart
nr', Map SlotNo NodeRestart
rs') -> SlotNo
-> ProtocolInfo blk
-> m [BlockForging m blk]
-> NodeRestart
-> Map SlotNo NodeRestart
-> m ()
loop SlotNo
s' ProtocolInfo blk
pInfo' m [BlockForging m blk]
blockForging' NodeRestart
nr' Map SlotNo NodeRestart
rs'
forkInstrumentation
:: OracularClock m
-> ResourceRegistry m
-> VertexStatusVar m blk
-> NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
-> StrictTVar m SlotNo
-> m ()
forkInstrumentation :: OracularClock m
-> ResourceRegistry m
-> StrictTVar m (VertexStatus m blk)
-> NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
-> StrictTVar m SlotNo
-> m ()
forkInstrumentation
OracularClock m
clock
ResourceRegistry m
registry
StrictTVar m (VertexStatus m blk)
vertexStatusVar
NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
nodeInfo
StrictTVar m SlotNo
nextInstrSlotVar =
m (m ()) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (m ()) -> m ()) -> m (m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ ResourceRegistry m
-> OracularClock m -> String -> (SlotNo -> m ()) -> m (m ())
forall (m :: * -> *).
HasCallStack =>
ResourceRegistry m
-> OracularClock m -> String -> (SlotNo -> m ()) -> m (m ())
OracularClock.forkEachSlot ResourceRegistry m
registry OracularClock m
clock String
lbl ((SlotNo -> m ()) -> m (m ())) -> (SlotNo -> m ()) -> m (m ())
forall a b. (a -> b) -> a -> b
$ \SlotNo
s -> do
bno <- STM m (WithOrigin BlockNo) -> m (WithOrigin BlockNo)
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m (WithOrigin BlockNo) -> m (WithOrigin BlockNo))
-> STM m (WithOrigin BlockNo) -> m (WithOrigin BlockNo)
forall a b. (a -> b) -> a -> b
$ StrictTVar m (VertexStatus m blk) -> STM m (VertexStatus m blk)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m (VertexStatus m blk)
vertexStatusVar STM m (VertexStatus m blk)
-> (VertexStatus m blk -> STM m (WithOrigin BlockNo))
-> STM m (WithOrigin BlockNo)
forall a b. STM m a -> (a -> STM m b) -> STM m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
VUp NodeKernel m NodeId Void blk
kernel LimitedApp m NodeId blk
_ -> ChainDB m blk -> STM m (WithOrigin BlockNo)
forall (m :: * -> *) blk.
(Monad (STM m), HasHeader (Header blk)) =>
ChainDB m blk -> STM m (WithOrigin BlockNo)
ChainDB.getTipBlockNo (NodeKernel m NodeId Void blk -> ChainDB m blk
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk -> ChainDB m blk
getChainDB NodeKernel m NodeId Void blk
kernel)
VertexStatus m blk
_ -> STM m (WithOrigin BlockNo)
forall a. STM m a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
traceWith nodeEventsTipBlockNos (s, bno)
atomically $ modifyTVar nextInstrSlotVar $ max (succ s)
where
NodeInfo{NodeEvents blk (Tracer m)
nodeInfoEvents :: NodeEvents blk (Tracer m)
nodeInfoEvents :: forall blk db (ev :: * -> *).
NodeInfo blk db ev -> NodeEvents blk ev
nodeInfoEvents} = NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
nodeInfo
NodeEvents{Tracer m (SlotNo, WithOrigin BlockNo)
nodeEventsTipBlockNos :: Tracer m (SlotNo, WithOrigin BlockNo)
nodeEventsTipBlockNos :: forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (SlotNo, WithOrigin BlockNo)
nodeEventsTipBlockNos} = NodeEvents blk (Tracer m)
nodeInfoEvents
lbl :: String
lbl = String
"instrumentation"
forkCrucialTxs
:: HasCallStack
=> OracularClock m
-> SlotNo
-> ResourceRegistry m
-> (SlotNo -> STM m ())
-> STM m (Point blk)
-> (ResourceRegistry m -> m (ReadOnlyForker' m blk))
-> Mempool m blk
-> [GenTx blk]
-> m ()
forkCrucialTxs :: HasCallStack =>
OracularClock m
-> SlotNo
-> ResourceRegistry m
-> (SlotNo -> STM m ())
-> STM m (Point blk)
-> (ResourceRegistry m -> m (ReadOnlyForker' m blk))
-> Mempool m blk
-> [GenTx blk]
-> m ()
forkCrucialTxs OracularClock m
clock SlotNo
s0 ResourceRegistry m
registry SlotNo -> STM m ()
unblockForge STM m (Point blk)
getTipPoint ResourceRegistry m -> m (ReadOnlyForker' m blk)
mforker Mempool m blk
mempool [GenTx blk]
txs0 = do
m (Thread m Any) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (Thread m Any) -> m ()) -> m (Thread m Any) -> m ()
forall a b. (a -> b) -> a -> b
$ ResourceRegistry m -> String -> m Any -> m (Thread m Any)
forall (m :: * -> *) a.
(MonadAsync m, MonadFork m, MonadMask m, HasCallStack) =>
ResourceRegistry m -> String -> m a -> m (Thread m a)
forkLinkedThread ResourceRegistry m
registry String
"crucialTxs" (m Any -> m (Thread m Any)) -> m Any -> m (Thread m Any)
forall a b. (a -> b) -> a -> b
$ (ResourceRegistry m -> m Any) -> m Any
forall (m :: * -> *) a.
(MonadSTM m, MonadMask m, MonadThread m, HasCallStack) =>
(ResourceRegistry m -> m a) -> m a
withRegistry ((ResourceRegistry m -> m Any) -> m Any)
-> (ResourceRegistry m -> m Any) -> m Any
forall a b. (a -> b) -> a -> b
$ \ResourceRegistry m
reg -> do
let loop :: (SlotNo, [TicketNo]) -> m Any
loop (SlotNo
slot, [TicketNo]
mempFp) = do
forker <- ResourceRegistry m -> m (ReadOnlyForker' m blk)
mforker ResourceRegistry m
reg
extLedger <- atomically $ roforkerGetLedgerState forker
let ledger = ExtLedgerState blk EmptyMK -> LedgerState blk EmptyMK
forall blk (mk :: MapKind).
ExtLedgerState blk mk -> LedgerState blk mk
ledgerState ExtLedgerState blk EmptyMK
extLedger
roforkerClose forker
_ <- addTxs mempool txs0
atomically $ unblockForge slot
let
slotChanged = do
let slot' :: SlotNo
slot' = SlotNo -> SlotNo
forall a. Enum a => a -> a
succ SlotNo
slot
_ <- OracularClock m -> SlotNo -> m Bool
forall (m :: * -> *). OracularClock m -> SlotNo -> m Bool
OracularClock.blockUntilSlot OracularClock m
clock SlotNo
slot'
pure (slot', mempFp)
mempChanged = do
let prjTno :: (a, TicketNo, c) -> TicketNo
prjTno (a
_a, TicketNo
b, c
_c) = TicketNo
b :: TicketNo
getMemp :: STM m [TicketNo]
getMemp = (((Validated (GenTx blk), TicketNo, TxMeasure blk) -> TicketNo)
-> [(Validated (GenTx blk), TicketNo, TxMeasure blk)] -> [TicketNo]
forall a b. (a -> b) -> [a] -> [b]
map (Validated (GenTx blk), TicketNo, TxMeasure blk) -> TicketNo
forall {a} {c}. (a, TicketNo, c) -> TicketNo
prjTno ([(Validated (GenTx blk), TicketNo, TxMeasure blk)] -> [TicketNo])
-> (MempoolSnapshot blk
-> [(Validated (GenTx blk), TicketNo, TxMeasure blk)])
-> MempoolSnapshot blk
-> [TicketNo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MempoolSnapshot blk
-> [(Validated (GenTx blk), TicketNo, TxMeasure blk)]
forall blk.
MempoolSnapshot blk
-> [(Validated (GenTx blk), TicketNo, TxMeasure blk)]
snapshotTxs) (MempoolSnapshot blk -> [TicketNo])
-> STM m (MempoolSnapshot blk) -> STM m [TicketNo]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mempool m blk -> STM m (MempoolSnapshot blk)
forall (m :: * -> *) blk.
Mempool m blk -> STM m (MempoolSnapshot blk)
getSnapshot Mempool m blk
mempool
(mempFp', _) <- STM m ([TicketNo], [TicketNo]) -> m ([TicketNo], [TicketNo])
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m ([TicketNo], [TicketNo]) -> m ([TicketNo], [TicketNo]))
-> STM m ([TicketNo], [TicketNo]) -> m ([TicketNo], [TicketNo])
forall a b. (a -> b) -> a -> b
$ ([TicketNo] -> [TicketNo])
-> [TicketNo] -> STM m [TicketNo] -> STM m ([TicketNo], [TicketNo])
forall (m :: * -> *) a b.
(MonadSTM m, Eq b) =>
(a -> b) -> b -> STM m a -> STM m (a, b)
blockUntilChanged [TicketNo] -> [TicketNo]
forall a. a -> a
id [TicketNo]
mempFp STM m [TicketNo]
getMemp
pure (slot, mempFp')
ldgrChanged = do
_ <- STM m (Point blk, Point blk) -> m (Point blk, Point blk)
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m (Point blk, Point blk) -> m (Point blk, Point blk))
-> STM m (Point blk, Point blk) -> m (Point blk, Point blk)
forall a b. (a -> b) -> a -> b
$ (Point blk -> Point blk)
-> Point blk -> STM m (Point blk) -> STM m (Point blk, Point blk)
forall (m :: * -> *) a b.
(MonadSTM m, Eq b) =>
(a -> b) -> b -> STM m a -> STM m (a, b)
blockUntilChanged Point blk -> Point blk
forall a. a -> a
id (LedgerState blk EmptyMK -> Point blk
forall blk (mk :: MapKind).
UpdateLedger blk =>
LedgerState blk mk -> Point blk
ledgerTipPoint LedgerState blk EmptyMK
ledger) STM m (Point blk)
getTipPoint
pure (slot, mempFp)
fps' <- fmap (either (either id id) id) $
slotChanged `race` mempChanged `race` ldgrChanged
void $ syncWithLedger mempool
loop fps'
(SlotNo, [TicketNo]) -> m Any
loop (SlotNo
s0, [])
forkTxProducer :: HasCallStack
=> CoreNodeId
-> ResourceRegistry m
-> OracularClock m
-> TopLevelConfig blk
-> Seed
-> (ResourceRegistry m -> m (ReadOnlyForker' m blk))
-> Mempool m blk
-> m ()
forkTxProducer :: HasCallStack =>
CoreNodeId
-> ResourceRegistry m
-> OracularClock m
-> TopLevelConfig blk
-> Seed
-> (ResourceRegistry m -> m (ReadOnlyForker' m blk))
-> Mempool m blk
-> m ()
forkTxProducer CoreNodeId
coreNodeId ResourceRegistry m
registry OracularClock m
clock TopLevelConfig blk
cfg Seed
nodeSeed ResourceRegistry m -> m (ReadOnlyForker' m blk)
mforker Mempool m blk
mempool =
m (m ()) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (m ()) -> m ()) -> m (m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ ResourceRegistry m
-> OracularClock m -> String -> (SlotNo -> m ()) -> m (m ())
forall (m :: * -> *).
HasCallStack =>
ResourceRegistry m
-> OracularClock m -> String -> (SlotNo -> m ()) -> m (m ())
OracularClock.forkEachSlot ResourceRegistry m
registry OracularClock m
clock String
"txProducer" ((SlotNo -> m ()) -> m (m ())) -> (SlotNo -> m ()) -> m (m ())
forall a b. (a -> b) -> a -> b
$ \SlotNo
curSlotNo -> (ResourceRegistry m -> m ()) -> m ()
forall (m :: * -> *) a.
(MonadSTM m, MonadMask m, MonadThread m, HasCallStack) =>
(ResourceRegistry m -> m a) -> m a
withRegistry ((ResourceRegistry m -> m ()) -> m ())
-> (ResourceRegistry m -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \ResourceRegistry m
reg -> do
forker <- ResourceRegistry m -> m (ReadOnlyForker' m blk)
mforker ResourceRegistry m
reg
emptySt' <- atomically $ roforkerGetLedgerState forker
let emptySt = ExtLedgerState blk EmptyMK
emptySt'
doRangeQuery = ReadOnlyForker' m blk
-> RangeQueryPrevious (ExtLedgerState blk)
-> m (LedgerTables (ExtLedgerState blk) ValuesMK)
forall (m :: * -> *) (l :: LedgerStateKind) blk.
ReadOnlyForker m l blk
-> RangeQueryPrevious l -> m (LedgerTables l ValuesMK)
roforkerRangeReadTables ReadOnlyForker' m blk
forker
fullLedgerSt <- fmap ledgerState $ do
fullUTxO <- doRangeQuery NoPreviousQuery
pure $! withLedgerTables emptySt fullUTxO
roforkerClose forker
let txs = Seed -> Gen [GenTx blk] -> [GenTx blk]
forall a. Seed -> Gen a -> a
runGen
(Seed
nodeSeed Seed -> Word64 -> Seed
forall a. Integral a => Seed -> a -> Seed
`combineWith` SlotNo -> Word64
unSlotNo SlotNo
curSlotNo)
(CoreNodeId
-> NumCoreNodes
-> SlotNo
-> TopLevelConfig blk
-> TxGenExtra blk
-> LedgerState blk ValuesMK
-> Gen [GenTx blk]
forall blk.
TxGen blk =>
CoreNodeId
-> NumCoreNodes
-> SlotNo
-> TopLevelConfig blk
-> TxGenExtra blk
-> LedgerState blk ValuesMK
-> Gen [GenTx blk]
testGenTxs CoreNodeId
coreNodeId NumCoreNodes
numCoreNodes SlotNo
curSlotNo TopLevelConfig blk
cfg TxGenExtra blk
txGenExtra LedgerState blk ValuesMK
fullLedgerSt)
void $ addTxs mempool txs
mkArgs :: ResourceRegistry m
-> TopLevelConfig blk
-> ExtLedgerState blk ValuesMK
-> Tracer m (RealPoint blk, ExtValidationError blk)
-> Tracer m (RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
-> Tracer m (LedgerUpdate blk)
-> Tracer m (ChainDB.TracePipeliningEvent blk)
-> NodeDBs (StrictTMVar m MockFS)
-> CoreNodeId
-> ChainDbArgs Identity m blk
mkArgs :: ResourceRegistry m
-> TopLevelConfig blk
-> ExtLedgerState blk ValuesMK
-> Tracer m (RealPoint blk, ExtValidationError blk)
-> Tracer m (RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
-> Tracer m (LedgerUpdate blk)
-> Tracer m (TracePipeliningEvent blk)
-> NodeDBs (StrictTMVar m MockFS)
-> CoreNodeId
-> ChainDbArgs Identity m blk
mkArgs
ResourceRegistry m
registry
TopLevelConfig blk
cfg ExtLedgerState blk ValuesMK
initLedger
Tracer m (RealPoint blk, ExtValidationError blk)
invalidTracer Tracer m (RealPoint blk, BlockNo)
addTracer Tracer m (RealPoint blk, BlockNo)
selTracer Tracer m (LedgerUpdate blk)
updatesTracer Tracer m (TracePipeliningEvent blk)
pipeliningTracer
NodeDBs (StrictTMVar m MockFS)
nodeDBs CoreNodeId
_coreNodeId =
let args :: ChainDbArgs Identity m blk
args = MinimalChainDbArgs m blk -> ChainDbArgs Identity m blk
forall (m :: * -> *) blk.
(MonadThrow m, MonadSTM m, ConsensusProtocol (BlockProtocol blk),
PrimMonad m) =>
MinimalChainDbArgs m blk -> Complete ChainDbArgs m blk
fromMinimalChainDbArgs MinimalChainDbArgs {
mcdbTopLevelConfig :: TopLevelConfig blk
mcdbTopLevelConfig = TopLevelConfig blk
cfg
, mcdbChunkInfo :: ChunkInfo
mcdbChunkInfo = EpochSize -> ChunkInfo
ImmutableDB.simpleChunkInfo EpochSize
epochSize0
, mcdbInitLedger :: ExtLedgerState blk ValuesMK
mcdbInitLedger = ExtLedgerState blk ValuesMK
initLedger
, mcdbRegistry :: ResourceRegistry m
mcdbRegistry = ResourceRegistry m
registry
, mcdbNodeDBs :: NodeDBs (StrictTMVar m MockFS)
mcdbNodeDBs = NodeDBs (StrictTMVar m MockFS)
nodeDBs
}
tr :: Tracer m (TraceEvent blk)
tr = Tracer m (TraceEvent blk)
instrumentationTracer Tracer m (TraceEvent blk)
-> Tracer m (TraceEvent blk) -> Tracer m (TraceEvent blk)
forall a. Semigroup a => a -> a -> a
<> Tracer m (TraceEvent blk)
forall (m :: * -> *) a. (Applicative m, Show a) => Tracer m a
nullDebugTracer
in ChainDbArgs Identity m blk
args { cdbImmDbArgs = (cdbImmDbArgs args) {
ImmutableDB.immCheckIntegrity = nodeCheckIntegrity (configStorage cfg)
, ImmutableDB.immTracer = TraceImmutableDBEvent >$< tr
}
, cdbVolDbArgs = (cdbVolDbArgs args) {
VolatileDB.volCheckIntegrity = nodeCheckIntegrity (configStorage cfg)
, VolatileDB.volTracer = TraceVolatileDBEvent >$< tr
}
, cdbLgrDbArgs = (cdbLgrDbArgs args) {
LedgerDB.lgrTracer = TraceLedgerDBEvent >$< tr
}
, cdbsArgs = (cdbsArgs args) {
cdbsGcDelay = 0
, cdbsTracer = instrumentationTracer <> nullDebugTracer
}
}
where
prj :: AnchoredFragment block -> BlockNo
prj AnchoredFragment block
af = case AnchoredFragment block -> WithOrigin BlockNo
forall block.
HasHeader block =>
AnchoredFragment block -> WithOrigin BlockNo
AF.headBlockNo AnchoredFragment block
af of
At BlockNo
bno -> BlockNo
bno
WithOrigin BlockNo
Origin -> String -> BlockNo
forall a. HasCallStack => String -> a
error String
"selTracer"
instrumentationTracer :: Tracer m (TraceEvent blk)
instrumentationTracer = (TraceEvent blk -> m ()) -> Tracer m (TraceEvent blk)
forall (m :: * -> *) a. (a -> m ()) -> Tracer m a
Tracer ((TraceEvent blk -> m ()) -> Tracer m (TraceEvent blk))
-> (TraceEvent blk -> m ()) -> Tracer m (TraceEvent blk)
forall a b. (a -> b) -> a -> b
$ \case
ChainDB.TraceAddBlockEvent
(ChainDB.AddBlockValidation (ChainDB.InvalidBlock ExtValidationError blk
e RealPoint blk
p))
-> Tracer m (RealPoint blk, ExtValidationError blk)
-> (RealPoint blk, ExtValidationError blk) -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (RealPoint blk, ExtValidationError blk)
invalidTracer (RealPoint blk
p, ExtValidationError blk
e)
ChainDB.TraceAddBlockEvent
(ChainDB.AddedBlockToVolatileDB RealPoint blk
p BlockNo
bno IsEBB
IsNotEBB Enclosing' ()
FallingEdge)
-> Tracer m (RealPoint blk, BlockNo)
-> (RealPoint blk, BlockNo) -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (RealPoint blk, BlockNo)
addTracer (RealPoint blk
p, BlockNo
bno)
ChainDB.TraceAddBlockEvent
(ChainDB.AddedToCurrentChain [LedgerEvent blk]
events SelectionChangedInfo blk
p AnchoredFragment (Header blk)
_old AnchoredFragment (Header blk)
new)
-> let ([LedgerWarning blk]
warnings, [LedgerUpdate blk]
updates) = [LedgerEvent blk] -> ([LedgerWarning blk], [LedgerUpdate blk])
forall blk.
[LedgerEvent blk] -> ([LedgerWarning blk], [LedgerUpdate blk])
partitionLedgerEvents [LedgerEvent blk]
events in
Either String () -> m () -> m ()
forall a. HasCallStack => Either String () -> a -> a
assertWithMsg ([LedgerWarning blk] -> Either String ()
forall a. Show a => [a] -> Either String ()
noWarnings [LedgerWarning blk]
warnings) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
(LedgerUpdate blk -> m ()) -> [LedgerUpdate blk] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Tracer m (LedgerUpdate blk) -> LedgerUpdate blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (LedgerUpdate blk)
updatesTracer) [LedgerUpdate blk]
updates
Tracer m (RealPoint blk, BlockNo)
-> (RealPoint blk, BlockNo) -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (RealPoint blk, BlockNo)
selTracer (SelectionChangedInfo blk -> RealPoint blk
forall blk. SelectionChangedInfo blk -> RealPoint blk
ChainDB.newTipPoint SelectionChangedInfo blk
p, AnchoredFragment (Header blk) -> BlockNo
forall {block}.
HasHeader block =>
AnchoredFragment block -> BlockNo
prj AnchoredFragment (Header blk)
new)
ChainDB.TraceAddBlockEvent
(ChainDB.SwitchedToAFork [LedgerEvent blk]
events SelectionChangedInfo blk
p AnchoredFragment (Header blk)
_old AnchoredFragment (Header blk)
new)
-> let ([LedgerWarning blk]
warnings, [LedgerUpdate blk]
updates) = [LedgerEvent blk] -> ([LedgerWarning blk], [LedgerUpdate blk])
forall blk.
[LedgerEvent blk] -> ([LedgerWarning blk], [LedgerUpdate blk])
partitionLedgerEvents [LedgerEvent blk]
events in
Either String () -> m () -> m ()
forall a. HasCallStack => Either String () -> a -> a
assertWithMsg ([LedgerWarning blk] -> Either String ()
forall a. Show a => [a] -> Either String ()
noWarnings [LedgerWarning blk]
warnings) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
(LedgerUpdate blk -> m ()) -> [LedgerUpdate blk] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Tracer m (LedgerUpdate blk) -> LedgerUpdate blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (LedgerUpdate blk)
updatesTracer) [LedgerUpdate blk]
updates
Tracer m (RealPoint blk, BlockNo)
-> (RealPoint blk, BlockNo) -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (RealPoint blk, BlockNo)
selTracer (SelectionChangedInfo blk -> RealPoint blk
forall blk. SelectionChangedInfo blk -> RealPoint blk
ChainDB.newTipPoint SelectionChangedInfo blk
p, AnchoredFragment (Header blk) -> BlockNo
forall {block}.
HasHeader block =>
AnchoredFragment block -> BlockNo
prj AnchoredFragment (Header blk)
new)
ChainDB.TraceAddBlockEvent
(ChainDB.PipeliningEvent TracePipeliningEvent blk
e)
-> Tracer m (TracePipeliningEvent blk)
-> TracePipeliningEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (TracePipeliningEvent blk)
pipeliningTracer TracePipeliningEvent blk
e
TraceEvent blk
_ -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
noWarnings :: Show a => [a] -> Either String ()
noWarnings :: forall a. Show a => [a] -> Either String ()
noWarnings [] = () -> Either String ()
forall a b. b -> Either a b
Right ()
noWarnings [a]
ws = String -> Either String ()
forall a b. a -> Either a b
Left (String -> Either String ()) -> String -> Either String ()
forall a b. (a -> b) -> a -> b
$ String
"Unexpected warnings: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [a] -> String
forall a. Show a => a -> String
show [a]
ws
_decorateId :: CoreNodeId -> Tracer m String -> Tracer m String
_decorateId :: CoreNodeId -> Tracer m String -> Tracer m String
_decorateId (CoreNodeId Word64
cid) = ShowS -> Tracer m String -> Tracer m String
forall a' a. (a' -> a) -> Tracer m a -> Tracer m a'
forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap (ShowS -> Tracer m String -> Tracer m String)
-> ShowS -> Tracer m String -> Tracer m String
forall a b. (a -> b) -> a -> b
$ \String
s ->
Word64 -> String
forall a. Show a => a -> String
show Word64
cid String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" | " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
s
forkNode
:: HasCallStack
=> CoreNodeId
-> OracularClock m
-> SlotNo
-> ResourceRegistry m
-> ProtocolInfo blk
-> m [BlockForging m blk]
-> NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
-> [GenTx blk]
-> m ( NodeKernel m NodeId Void blk
, LimitedApp m NodeId blk
)
forkNode :: HasCallStack =>
CoreNodeId
-> OracularClock m
-> SlotNo
-> ResourceRegistry m
-> ProtocolInfo blk
-> m [BlockForging m blk]
-> NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
-> [GenTx blk]
-> m (NodeKernel m NodeId Void blk, LimitedApp m NodeId blk)
forkNode CoreNodeId
coreNodeId OracularClock m
clock SlotNo
joinSlot ResourceRegistry m
registry ProtocolInfo blk
pInfo m [BlockForging m blk]
blockForging NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
nodeInfo [GenTx blk]
txs0 = do
let ProtocolInfo{TopLevelConfig blk
ExtLedgerState blk ValuesMK
pInfoInitLedger :: forall b. ProtocolInfo b -> ExtLedgerState b ValuesMK
pInfoConfig :: forall b. ProtocolInfo b -> TopLevelConfig b
pInfoConfig :: TopLevelConfig blk
pInfoInitLedger :: ExtLedgerState blk ValuesMK
..} = ProtocolInfo blk
pInfo
let NodeInfo
{ NodeEvents blk (Tracer m)
nodeInfoEvents :: forall blk db (ev :: * -> *).
NodeInfo blk db ev -> NodeEvents blk ev
nodeInfoEvents :: NodeEvents blk (Tracer m)
nodeInfoEvents
, NodeDBs (StrictTMVar m MockFS)
nodeInfoDBs :: NodeDBs (StrictTMVar m MockFS)
nodeInfoDBs :: forall blk db (ev :: * -> *). NodeInfo blk db ev -> NodeDBs db
nodeInfoDBs
} = NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
nodeInfo
let invalidTracer :: Tracer m (RealPoint blk, ExtValidationError blk)
invalidTracer = NodeEvents blk (Tracer m)
-> Tracer m (RealPoint blk, ExtValidationError blk)
forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (RealPoint blk, ExtValidationError blk)
nodeEventsInvalids NodeEvents blk (Tracer m)
nodeInfoEvents
updatesTracer :: Tracer m (LedgerUpdate blk)
updatesTracer = NodeEvents blk (Tracer m) -> Tracer m (LedgerUpdate blk)
forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (LedgerUpdate blk)
nodeEventsUpdates NodeEvents blk (Tracer m)
nodeInfoEvents
wrapTracer :: Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
wrapTracer Tracer m (SlotNo, RealPoint blk, BlockNo)
tr = ((RealPoint blk, BlockNo) -> m ())
-> Tracer m (RealPoint blk, BlockNo)
forall (m :: * -> *) a. (a -> m ()) -> Tracer m a
Tracer (((RealPoint blk, BlockNo) -> m ())
-> Tracer m (RealPoint blk, BlockNo))
-> ((RealPoint blk, BlockNo) -> m ())
-> Tracer m (RealPoint blk, BlockNo)
forall a b. (a -> b) -> a -> b
$ \(RealPoint blk
p, BlockNo
bno) -> do
s <- OracularClock m -> m SlotNo
forall (m :: * -> *). OracularClock m -> m SlotNo
OracularClock.getCurrentSlot OracularClock m
clock
traceWith tr (s, p, bno)
addTracer :: Tracer m (RealPoint blk, BlockNo)
addTracer = Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
wrapTracer (Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo))
-> Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
forall a b. (a -> b) -> a -> b
$ NodeEvents blk (Tracer m)
-> Tracer m (SlotNo, RealPoint blk, BlockNo)
forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (SlotNo, RealPoint blk, BlockNo)
nodeEventsAdds NodeEvents blk (Tracer m)
nodeInfoEvents
selTracer :: Tracer m (RealPoint blk, BlockNo)
selTracer = Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
wrapTracer (Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo))
-> Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
forall a b. (a -> b) -> a -> b
$ NodeEvents blk (Tracer m)
-> Tracer m (SlotNo, RealPoint blk, BlockNo)
forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (SlotNo, RealPoint blk, BlockNo)
nodeEventsSelects NodeEvents blk (Tracer m)
nodeInfoEvents
headerAddTracer :: Tracer m (RealPoint blk, BlockNo)
headerAddTracer = Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
wrapTracer (Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo))
-> Tracer m (SlotNo, RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
forall a b. (a -> b) -> a -> b
$ NodeEvents blk (Tracer m)
-> Tracer m (SlotNo, RealPoint blk, BlockNo)
forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (SlotNo, RealPoint blk, BlockNo)
nodeEventsHeaderAdds NodeEvents blk (Tracer m)
nodeInfoEvents
pipeliningTracer :: Tracer m (TracePipeliningEvent blk)
pipeliningTracer = NodeEvents blk (Tracer m) -> Tracer m (TracePipeliningEvent blk)
forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (TracePipeliningEvent blk)
nodeEventsPipelining NodeEvents blk (Tracer m)
nodeInfoEvents
let chainDbArgs :: ChainDbArgs Identity m blk
chainDbArgs = ResourceRegistry m
-> TopLevelConfig blk
-> ExtLedgerState blk ValuesMK
-> Tracer m (RealPoint blk, ExtValidationError blk)
-> Tracer m (RealPoint blk, BlockNo)
-> Tracer m (RealPoint blk, BlockNo)
-> Tracer m (LedgerUpdate blk)
-> Tracer m (TracePipeliningEvent blk)
-> NodeDBs (StrictTMVar m MockFS)
-> CoreNodeId
-> ChainDbArgs Identity m blk
mkArgs
ResourceRegistry m
registry
TopLevelConfig blk
pInfoConfig ExtLedgerState blk ValuesMK
pInfoInitLedger
Tracer m (RealPoint blk, ExtValidationError blk)
invalidTracer
Tracer m (RealPoint blk, BlockNo)
addTracer
Tracer m (RealPoint blk, BlockNo)
selTracer
Tracer m (LedgerUpdate blk)
updatesTracer
Tracer m (TracePipeliningEvent blk)
pipeliningTracer
NodeDBs (StrictTMVar m MockFS)
nodeInfoDBs
CoreNodeId
coreNodeId
chainDB <- (ResourceKey m, ChainDB m blk) -> ChainDB m blk
forall a b. (a, b) -> b
snd ((ResourceKey m, ChainDB m blk) -> ChainDB m blk)
-> m (ResourceKey m, ChainDB m blk) -> m (ChainDB m blk)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ResourceRegistry m
-> (ResourceId -> m (ChainDB m blk))
-> (ChainDB m blk -> m ())
-> m (ResourceKey m, ChainDB m blk)
forall (m :: * -> *) a.
(MonadSTM m, MonadMask m, MonadThread m, HasCallStack) =>
ResourceRegistry m
-> (ResourceId -> m a) -> (a -> m ()) -> m (ResourceKey m, a)
allocate ResourceRegistry m
registry (m (ChainDB m blk) -> ResourceId -> m (ChainDB m blk)
forall a b. a -> b -> a
const (ChainDbArgs Identity m blk -> m (ChainDB m blk)
forall (m :: * -> *) blk.
(IOLike m, LedgerSupportsProtocol blk,
BlockSupportsDiffusionPipelining blk, InspectLedger blk,
HasHardForkHistory blk, ConvertRawHash blk,
SerialiseDiskConstraints blk, LedgerSupportsLedgerDB blk) =>
Complete ChainDbArgs m blk -> m (ChainDB m blk)
ChainDB.openDB ChainDbArgs Identity m blk
chainDbArgs)) ChainDB m blk -> m ()
forall (m :: * -> *) blk. ChainDB m blk -> m ()
ChainDB.closeDB
let customForgeBlock ::
BlockForging m blk
-> TopLevelConfig blk
-> BlockNo
-> SlotNo
-> TickedLedgerState blk mk
-> [Validated (GenTx blk)]
-> IsLeader (BlockProtocol blk)
-> m blk
customForgeBlock BlockForging m blk
origBlockForging TopLevelConfig blk
cfg' BlockNo
currentBno SlotNo
currentSlot TickedLedgerState blk mk
tickedLdgSt [Validated (GenTx blk)]
txs IsLeader (BlockProtocol blk)
prf = do
let currentEpoch :: EpochNo
currentEpoch = Future -> SlotNo -> EpochNo
HFF.futureSlotToEpoch Future
future SlotNo
currentSlot
let inFirstEra :: Bool
inFirstEra = Future -> EpochNo -> Bool
HFF.futureEpochInFirstEra Future
future EpochNo
currentEpoch
let ebbSlot :: SlotNo
ebbSlot :: SlotNo
ebbSlot = Word64 -> SlotNo
SlotNo (Word64 -> SlotNo) -> Word64 -> SlotNo
forall a b. (a -> b) -> a -> b
$ Word64
x Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
* Word64
y
where
EpochNo Word64
x = EpochNo
currentEpoch
EpochSize Word64
y = EpochSize
epochSize0
let p :: Point blk
p :: Point blk
p = Point (Ticked (LedgerState blk)) -> Point blk
forall {k1} {k2} (b :: k1) (b' :: k2).
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint (Point (Ticked (LedgerState blk)) -> Point blk)
-> Point (Ticked (LedgerState blk)) -> Point blk
forall a b. (a -> b) -> a -> b
$ TickedLedgerState blk mk -> Point (Ticked (LedgerState blk))
forall (mk :: MapKind).
Ticked (LedgerState blk) mk -> Point (Ticked (LedgerState blk))
forall (l :: LedgerStateKind) (mk :: MapKind).
GetTip l =>
l mk -> Point l
getTip TickedLedgerState blk mk
tickedLdgSt
let needEBB :: Bool
needEBB = Bool
inFirstEra Bool -> Bool -> Bool
&& SlotNo -> WithOrigin SlotNo
forall t. t -> WithOrigin t
NotOrigin SlotNo
ebbSlot WithOrigin SlotNo -> WithOrigin SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
> Point blk -> WithOrigin SlotNo
forall {k} (block :: k). Point block -> WithOrigin SlotNo
pointSlot Point blk
p
case Maybe (ForgeEbbEnv blk)
mbForgeEbbEnv Maybe (ForgeEbbEnv blk) -> Maybe () -> Maybe (ForgeEbbEnv blk)
forall a b. Maybe a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
needEBB of
Maybe (ForgeEbbEnv blk)
Nothing ->
BlockForging m blk
-> TopLevelConfig blk
-> BlockNo
-> SlotNo
-> TickedLedgerState blk EmptyMK
-> [Validated (GenTx blk)]
-> IsLeader (BlockProtocol blk)
-> m blk
forall (m :: * -> *) blk.
BlockForging m blk
-> TopLevelConfig blk
-> BlockNo
-> SlotNo
-> TickedLedgerState blk EmptyMK
-> [Validated (GenTx blk)]
-> IsLeader (BlockProtocol blk)
-> m blk
forgeBlock
BlockForging m blk
origBlockForging
TopLevelConfig blk
cfg'
BlockNo
currentBno
SlotNo
currentSlot
(TickedLedgerState blk mk -> TickedLedgerState blk EmptyMK
forall (l :: LedgerStateKind) (mk :: MapKind).
HasLedgerTables l =>
l mk -> l EmptyMK
forgetLedgerTables TickedLedgerState blk mk
tickedLdgSt)
[Validated (GenTx blk)]
txs
IsLeader (BlockProtocol blk)
prf
Just ForgeEbbEnv blk
forgeEbbEnv -> do
let ebbBno :: BlockNo
ebbBno = case BlockNo
currentBno of
BlockNo
0 -> String -> BlockNo
forall a. HasCallStack => String -> a
error String
"Error, only node initialization can forge non-EBB with block number 0."
BlockNo
n -> BlockNo -> BlockNo
forall a. Enum a => a -> a
pred BlockNo
n
let ebb :: blk
ebb = ForgeEbbEnv blk
-> TopLevelConfig blk -> SlotNo -> BlockNo -> ChainHash blk -> blk
forall blk.
ForgeEbbEnv blk
-> TopLevelConfig blk -> SlotNo -> BlockNo -> ChainHash blk -> blk
forgeEBB ForgeEbbEnv blk
forgeEbbEnv TopLevelConfig blk
pInfoConfig
SlotNo
ebbSlot BlockNo
ebbBno (Point blk -> ChainHash blk
forall {k} (block :: k). Point block -> ChainHash block
pointHash Point blk
p)
let apply :: blk
-> Ticked (LedgerState blk) ValuesMK
-> Except (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
apply = ComputeLedgerEvents
-> LedgerCfg (LedgerState blk)
-> blk
-> Ticked (LedgerState blk) ValuesMK
-> Except (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
forall (l :: LedgerStateKind) blk.
(ApplyBlock l blk, HasCallStack) =>
ComputeLedgerEvents
-> LedgerCfg l
-> blk
-> Ticked l ValuesMK
-> Except (LedgerErr l) (l DiffMK)
applyLedgerBlock ComputeLedgerEvents
OmitLedgerEvents (TopLevelConfig blk -> LedgerCfg (LedgerState blk)
forall blk. TopLevelConfig blk -> LedgerConfig blk
configLedger TopLevelConfig blk
pInfoConfig)
tables :: LedgerTables (Ticked (LedgerState blk)) ValuesMK
tables = LedgerTables (Ticked (LedgerState blk)) ValuesMK
forall (mk :: MapKind) (l :: LedgerStateKind).
(ZeroableMK mk, LedgerTableConstraints l) =>
LedgerTables l mk
emptyLedgerTables
tickedLdgSt' <- case Except (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
-> Either (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
forall e a. Except e a -> Either e a
Exc.runExcept (Except (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
-> Either (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK))
-> Except (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
-> Either (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
forall a b. (a -> b) -> a -> b
$ blk
-> Ticked (LedgerState blk) ValuesMK
-> Except (LedgerErr (LedgerState blk)) (LedgerState blk DiffMK)
apply blk
ebb (TickedLedgerState blk mk
tickedLdgSt TickedLedgerState blk mk
-> LedgerTables (Ticked (LedgerState blk)) ValuesMK
-> Ticked (LedgerState blk) ValuesMK
forall (mk :: MapKind) (any :: MapKind).
(CanMapMK mk, CanMapKeysMK mk, ZeroableMK mk) =>
Ticked (LedgerState blk) any
-> LedgerTables (Ticked (LedgerState blk)) mk
-> Ticked (LedgerState blk) mk
forall (l :: LedgerStateKind) (mk :: MapKind) (any :: MapKind).
(HasLedgerTables l, CanMapMK mk, CanMapKeysMK mk, ZeroableMK mk) =>
l any -> LedgerTables l mk -> l mk
`withLedgerTables` LedgerTables (Ticked (LedgerState blk)) ValuesMK
tables) of
Left LedgerErr (LedgerState blk)
e -> JitEbbError blk -> m (Ticked (LedgerState blk) DiffMK)
forall a e. (HasCallStack, Exception e) => e -> a
Exn.throw (JitEbbError blk -> m (Ticked (LedgerState blk) DiffMK))
-> JitEbbError blk -> m (Ticked (LedgerState blk) DiffMK)
forall a b. (a -> b) -> a -> b
$ forall blk. LedgerError blk -> JitEbbError blk
JitEbbError @blk LedgerErr (LedgerState blk)
e
Right LedgerState blk DiffMK
st -> Ticked (LedgerState blk) DiffMK
-> m (Ticked (LedgerState blk) DiffMK)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Ticked (LedgerState blk) DiffMK
-> m (Ticked (LedgerState blk) DiffMK))
-> Ticked (LedgerState blk) DiffMK
-> m (Ticked (LedgerState blk) DiffMK)
forall a b. (a -> b) -> a -> b
$ ComputeLedgerEvents
-> LedgerCfg (LedgerState blk)
-> SlotNo
-> LedgerState blk EmptyMK
-> Ticked (LedgerState blk) DiffMK
forall (l :: LedgerStateKind).
IsLedger l =>
ComputeLedgerEvents
-> LedgerCfg l -> SlotNo -> l EmptyMK -> Ticked l DiffMK
applyChainTick ComputeLedgerEvents
OmitLedgerEvents
(TopLevelConfig blk -> LedgerCfg (LedgerState blk)
forall blk. TopLevelConfig blk -> LedgerConfig blk
configLedger TopLevelConfig blk
pInfoConfig)
SlotNo
currentSlot
(LedgerState blk DiffMK -> LedgerState blk EmptyMK
forall (l :: LedgerStateKind) (mk :: MapKind).
HasLedgerTables l =>
l mk -> l EmptyMK
forgetLedgerTables LedgerState blk DiffMK
st)
blk <- forgeBlock
origBlockForging
cfg'
currentBno
currentSlot
(forgetLedgerTables tickedLdgSt')
txs
prf
void $ ChainDB.addBlock chainDB InvalidBlockPunishment.noPunishment ebb
pure blk
(unblockForge, blockOnCrucial) <- do
var <- uncheckedNewTVarM 0
pure
( \SlotNo
s -> do
StrictTVar m SlotNo -> (SlotNo -> SlotNo) -> STM m ()
forall (m :: * -> *) a.
MonadSTM m =>
StrictTVar m a -> (a -> a) -> STM m ()
modifyTVar StrictTVar m SlotNo
var (SlotNo -> SlotNo
forall a. Enum a => a -> a
succ SlotNo
s SlotNo -> SlotNo -> SlotNo
forall a. Ord a => a -> a -> a
`max`)
, \SlotNo
s -> do
sentinel <- StrictTVar m SlotNo -> STM m SlotNo
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m SlotNo
var
check $ s < sentinel
)
let
instrumentationTracers = Tracers m (ConnectionId NodeId) Any blk
forall (m :: * -> *) remotePeer localPeer blk.
Monad m =>
Tracers m remotePeer localPeer blk
nullTracers
{ chainSyncClientTracer = Tracer $ \case
TraceLabelPeer ConnectionId NodeId
_ (CSClient.TraceDownloadedHeader Header blk
hdr)
-> case Header blk -> Point (Header blk)
forall block. HasHeader block => block -> Point block
blockPoint Header blk
hdr of
Point (Header blk)
GenesisPoint -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
BlockPoint SlotNo
s HeaderHash (Header blk)
h ->
Tracer m (RealPoint blk, BlockNo)
-> (RealPoint blk, BlockNo) -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith Tracer m (RealPoint blk, BlockNo)
headerAddTracer
(SlotNo -> HeaderHash blk -> RealPoint blk
forall blk. SlotNo -> HeaderHash blk -> RealPoint blk
RealPoint SlotNo
s HeaderHash blk
HeaderHash (Header blk)
h, Header blk -> BlockNo
forall b. HasHeader b => b -> BlockNo
blockNo Header blk
hdr)
TraceLabelPeer
(ConnectionId NodeId) (TraceChainSyncClientEvent blk)
_ -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
, forgeTracer = Tracer $ \(TraceLabelCreds Text
_ TraceForgeEvent blk
ev) -> do
Tracer m (TraceForgeEvent blk) -> TraceForgeEvent blk -> m ()
forall (m :: * -> *) a. Tracer m a -> a -> m ()
traceWith (NodeEvents blk (Tracer m) -> Tracer m (TraceForgeEvent blk)
forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (TraceForgeEvent blk)
nodeEventsForges NodeEvents blk (Tracer m)
nodeInfoEvents) TraceForgeEvent blk
ev
case TraceForgeEvent blk
ev of
TraceNodeIsLeader SlotNo
s -> STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> STM m () -> m ()
forall a b. (a -> b) -> a -> b
$ SlotNo -> STM m ()
blockOnCrucial SlotNo
s
TraceForgeEvent blk
_ -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
}
tracers = Tracers' (ConnectionId NodeId) Void blk (Tracer m)
instrumentationTracers Tracers' (ConnectionId NodeId) Void blk (Tracer m)
-> Tracers' (ConnectionId NodeId) Void blk (Tracer m)
-> Tracers' (ConnectionId NodeId) Void blk (Tracer m)
forall a. Semigroup a => a -> a -> a
<> Tracers' (ConnectionId NodeId) Void blk (Tracer m)
forall (m :: * -> *) peer blk.
(Monad m, Show peer, LedgerSupportsProtocol blk,
TracingConstraints blk) =>
Tracers m peer Void blk
nullDebugTracers
let
hfbtBackoffDelay =
NominalDiffTime -> BackoffDelay
BackoffDelay (NominalDiffTime -> BackoffDelay)
-> m NominalDiffTime -> m BackoffDelay
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OracularClock m -> m NominalDiffTime
forall (m :: * -> *). OracularClock m -> m NominalDiffTime
OracularClock.delayUntilNextSlot OracularClock m
clock
btime <- hardForkBlockchainTime HardForkBlockchainTimeArgs
{ hfbtBackoffDelay
, hfbtGetLedgerState =
ledgerState <$> ChainDB.getCurrentLedger chainDB
, hfbtLedgerConfig = configLedger pInfoConfig
, hfbtRegistry = registry
, hfbtSystemTime = OracularClock.finiteSystemTime clock
, hfbtTracer =
contramap
(fmap (fromRelativeTime (SystemStart dawnOfTime)))
(blockchainTimeTracer tracers)
, hfbtMaxClockRewind = secondsToNominalDiffTime 0
}
let rng = case Seed
seed of
Seed Int
s -> Int -> StdGen
mkStdGen Int
s
(kaRng, psRng) = split rng
publicPeerSelectionStateVar <- makePublicPeerSelectionStateVar
let nodeKernelArgs = NodeKernelArgs
{ Tracers' (ConnectionId NodeId) Void blk (Tracer m)
tracers :: Tracers' (ConnectionId NodeId) Void blk (Tracer m)
tracers :: Tracers' (ConnectionId NodeId) Void blk (Tracer m)
tracers
, ResourceRegistry m
registry :: ResourceRegistry m
registry :: ResourceRegistry m
registry
, cfg :: TopLevelConfig blk
cfg = TopLevelConfig blk
pInfoConfig
, BlockchainTime m
btime :: BlockchainTime m
btime :: BlockchainTime m
btime
, ChainDB m blk
chainDB :: ChainDB m blk
chainDB :: ChainDB m blk
chainDB
, initChainDB :: StorageConfig blk -> InitChainDB m blk -> m ()
initChainDB = StorageConfig blk -> InitChainDB m blk -> m ()
forall blk (m :: * -> *).
(NodeInitStorage blk, IOLike m) =>
StorageConfig blk -> InitChainDB m blk -> m ()
forall (m :: * -> *).
IOLike m =>
StorageConfig blk -> InitChainDB m blk -> m ()
nodeInitChainDB
, chainSyncFutureCheck :: SomeHeaderInFutureCheck m blk
chainSyncFutureCheck =
ClockSkew -> SystemTime m -> SomeHeaderInFutureCheck m blk
forall blk (m :: * -> *).
(HasHeader blk, HasHeader (Header blk), HasHardForkHistory blk,
MonadDelay m) =>
ClockSkew -> SystemTime m -> SomeHeaderInFutureCheck m blk
InFutureCheck.realHeaderInFutureCheck
ClockSkew
InFutureCheck.defaultClockSkew
(OracularClock m -> SystemTime m
forall (m :: * -> *). OracularClock m -> SystemTime m
OracularClock.finiteSystemTime OracularClock m
clock)
, chainSyncHistoricityCheck :: m GsmState -> HistoricityCheck m blk
chainSyncHistoricityCheck = \m GsmState
_getGsmState -> HistoricityCheck m blk
forall (m :: * -> *) blk. Applicative m => HistoricityCheck m blk
HistoricityCheck.noCheck
, blockFetchSize :: Header blk -> SizeInBytes
blockFetchSize = Header blk -> SizeInBytes
forall blk.
SerialiseNodeToNodeConstraints blk =>
Header blk -> SizeInBytes
estimateBlockSize
, mempoolCapacityOverride :: MempoolCapacityBytesOverride
mempoolCapacityOverride = MempoolCapacityBytesOverride
NoMempoolCapacityBytesOverride
, keepAliveRng :: StdGen
keepAliveRng = StdGen
kaRng
, peerSharingRng :: StdGen
peerSharingRng = StdGen
psRng
, miniProtocolParameters :: MiniProtocolParameters
miniProtocolParameters = MiniProtocolParameters {
chainSyncPipeliningHighMark :: Word16
chainSyncPipeliningHighMark = Word16
4,
chainSyncPipeliningLowMark :: Word16
chainSyncPipeliningLowMark = Word16
2,
blockFetchPipeliningMax :: Word16
blockFetchPipeliningMax = Word16
10,
txSubmissionMaxUnacked :: NumTxIdsToAck
txSubmissionMaxUnacked = NumTxIdsToAck
1000
}
, blockFetchConfiguration :: BlockFetchConfiguration
blockFetchConfiguration = BlockFetchConfiguration {
bfcMaxConcurrencyBulkSync :: Word
bfcMaxConcurrencyBulkSync = Word
1
, bfcMaxConcurrencyDeadline :: Word
bfcMaxConcurrencyDeadline = Word
2
, bfcMaxRequestsInflight :: Word
bfcMaxRequestsInflight = Word
10
, bfcDecisionLoopIntervalPraos :: DiffTime
bfcDecisionLoopIntervalPraos = DiffTime
0.0
, bfcDecisionLoopIntervalGenesis :: DiffTime
bfcDecisionLoopIntervalGenesis = DiffTime
0.0
, bfcSalt :: Int
bfcSalt = Int
0
, bfcGenesisBFConfig :: GenesisBlockFetchConfiguration
bfcGenesisBFConfig = GenesisConfig -> GenesisBlockFetchConfiguration
gcBlockFetchConfig GenesisConfig
enableGenesisConfigDefault
}
, gsmArgs :: GsmNodeKernelArgs m blk
gsmArgs = GSM.GsmNodeKernelArgs {
gsmAntiThunderingHerd :: StdGen
gsmAntiThunderingHerd = StdGen
kaRng
, gsmDurationUntilTooOld :: Maybe (WrapDurationUntilTooOld m blk)
gsmDurationUntilTooOld = Maybe (WrapDurationUntilTooOld m blk)
forall a. Maybe a
Nothing
, gsmMarkerFileView :: MarkerFileView m
gsmMarkerFileView = GSM.MarkerFileView {
touchMarkerFile :: m ()
touchMarkerFile = () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
, removeMarkerFile :: m ()
removeMarkerFile = () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
, hasMarkerFile :: m Bool
hasMarkerFile = Bool -> m Bool
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
}
, gsmMinCaughtUpDuration :: NominalDiffTime
gsmMinCaughtUpDuration = NominalDiffTime
0
}
, getUseBootstrapPeers :: STM m UseBootstrapPeers
getUseBootstrapPeers = UseBootstrapPeers -> STM m UseBootstrapPeers
forall a. a -> STM m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UseBootstrapPeers
DontUseBootstrapPeers
, StrictTVar m (PublicPeerSelectionState NodeId)
publicPeerSelectionStateVar :: StrictTVar m (PublicPeerSelectionState NodeId)
publicPeerSelectionStateVar :: StrictTVar m (PublicPeerSelectionState NodeId)
publicPeerSelectionStateVar
, genesisArgs :: GenesisNodeKernelArgs m blk
genesisArgs = GenesisNodeKernelArgs {
gnkaLoEAndGDDArgs :: LoEAndGDDConfig (LoEAndGDDNodeKernelArgs m blk)
gnkaLoEAndGDDArgs = LoEAndGDDConfig (LoEAndGDDNodeKernelArgs m blk)
forall a. LoEAndGDDConfig a
LoEAndGDDDisabled
}
, getDiffusionPipeliningSupport :: DiffusionPipeliningSupport
getDiffusionPipeliningSupport = DiffusionPipeliningSupport
DiffusionPipeliningOn
}
nodeKernel <- initNodeKernel nodeKernelArgs
blockForging' <-
map (\BlockForging m blk
bf -> BlockForging m blk
bf { forgeBlock = customForgeBlock bf })
<$> blockForging
setBlockForging nodeKernel blockForging'
let mempool = NodeKernel m NodeId Void blk -> Mempool m blk
forall (m :: * -> *) addrNTN addrNTC blk.
NodeKernel m addrNTN addrNTC blk -> Mempool m blk
getMempool NodeKernel m NodeId Void blk
nodeKernel
let app = NodeKernel m NodeId Void blk
-> Tracers m NodeId blk CodecError
-> (NodeToNodeVersion
-> Codecs
blk
NodeId
CodecError
m
ByteString
ByteString
ByteString
ByteString
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing NodeId)))
-> ByteLimits
ByteString
ByteString
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
-> m ChainSyncTimeout
-> ChainSyncLoPBucketConfig
-> CSJConfig
-> ReportPeerMetrics m (ConnectionId NodeId)
-> Handlers m NodeId blk
-> Apps
m
NodeId
ByteString
ByteString
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing NodeId))
NodeToNodeInitiatorResult
()
forall (m :: * -> *) addrNTN addrNTC blk e bCS bBF bTX bKA bPS.
(IOLike m, MonadTimer m, Ord addrNTN, Exception e,
LedgerSupportsProtocol blk, ShowProxy blk, ShowProxy (Header blk),
ShowProxy (TxId (GenTx blk)), ShowProxy (GenTx blk)) =>
NodeKernel m addrNTN addrNTC blk
-> Tracers m addrNTN blk e
-> (NodeToNodeVersion
-> Codecs blk addrNTN e m bCS bCS bBF bBF bTX bKA bPS)
-> ByteLimits bCS bBF bTX bKA
-> m ChainSyncTimeout
-> ChainSyncLoPBucketConfig
-> CSJConfig
-> ReportPeerMetrics m (ConnectionId addrNTN)
-> Handlers m addrNTN blk
-> Apps m addrNTN bCS bBF bTX bKA bPS NodeToNodeInitiatorResult ()
NTN.mkApps
NodeKernel m NodeId Void blk
nodeKernel
Tracers m NodeId blk CodecError
forall (m :: * -> *) blk peer failure.
(Monad m, HasHeader blk, TracingConstraints blk, Show peer) =>
Tracers m peer blk failure
nullDebugProtocolTracers
(TopLevelConfig blk
-> NodeToNodeVersion
-> Codecs
blk
NodeId
CodecError
m
ByteString
ByteString
ByteString
ByteString
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing NodeId))
customNodeToNodeCodecs TopLevelConfig blk
pInfoConfig)
ByteLimits
ByteString
ByteString
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
forall bCS bBF bTX bKA. ByteLimits bCS bBF bTX bKA
NTN.noByteLimits
(ChainSyncTimeout -> m ChainSyncTimeout
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChainSyncTimeout -> m ChainSyncTimeout)
-> ChainSyncTimeout -> m ChainSyncTimeout
forall a b. (a -> b) -> a -> b
$ NTN.ChainSyncTimeout
{ canAwaitTimeout :: Maybe DiffTime
canAwaitTimeout = Maybe DiffTime
waitForever
, intersectTimeout :: Maybe DiffTime
intersectTimeout = Maybe DiffTime
waitForever
, mustReplyTimeout :: Maybe DiffTime
mustReplyTimeout = Maybe DiffTime
waitForever
, idleTimeout :: Maybe DiffTime
idleTimeout = Maybe DiffTime
waitForever
})
ChainSyncLoPBucketConfig
CSClient.ChainSyncLoPBucketDisabled
CSJConfig
CSClient.CSJDisabled
ReportPeerMetrics m (ConnectionId NodeId)
forall (m :: * -> *) p. MonadSTM m => ReportPeerMetrics m p
nullMetric
(NodeKernelArgs m NodeId Void blk
-> NodeKernel m NodeId Void blk -> Handlers m NodeId blk
forall (m :: * -> *) blk addrNTN addrNTC.
(IOLike m, MonadTime m, MonadTimer m, LedgerSupportsMempool blk,
HasTxId (GenTx blk), LedgerSupportsProtocol blk, Ord addrNTN,
Hashable addrNTN) =>
NodeKernelArgs m addrNTN addrNTC blk
-> NodeKernel m addrNTN addrNTC blk -> Handlers m addrNTN blk
NTN.mkHandlers NodeKernelArgs m NodeId Void blk
nodeKernelArgs NodeKernel m NodeId Void blk
nodeKernel)
let getForker ResourceRegistry m
rr = do
ChainDB m blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (ReadOnlyForker' m blk))
forall (m :: * -> *) blk.
ChainDB m blk
-> ResourceRegistry m
-> Target (Point blk)
-> m (Either GetForkerError (ReadOnlyForker' m blk))
ChainDB.getReadOnlyForkerAtPoint ChainDB m blk
chainDB ResourceRegistry m
rr Target (Point blk)
forall point. Target point
VolatileTip m (Either GetForkerError (ReadOnlyForker' m blk))
-> (Either GetForkerError (ReadOnlyForker' m blk)
-> m (ReadOnlyForker' m blk))
-> m (ReadOnlyForker' m blk)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left GetForkerError
e -> String -> m (ReadOnlyForker' m blk)
forall a. HasCallStack => String -> a
error (String -> m (ReadOnlyForker' m blk))
-> String -> m (ReadOnlyForker' m blk)
forall a b. (a -> b) -> a -> b
$ GetForkerError -> String
forall a. Show a => a -> String
show GetForkerError
e
Right ReadOnlyForker' m blk
l -> ReadOnlyForker' m blk -> m (ReadOnlyForker' m blk)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReadOnlyForker' m blk
l
forkCrucialTxs
clock
joinSlot
registry
unblockForge
(ledgerTipPoint . ledgerState <$> ChainDB.getCurrentLedger chainDB)
getForker
mempool
txs0
forkTxProducer
coreNodeId
registry
clock
pInfoConfig
(seed `combineWith` unCoreNodeId coreNodeId)
getForker
mempool
return (nodeKernel, LimitedApp app)
customNodeToNodeCodecs
:: TopLevelConfig blk
-> NodeToNodeVersion
-> NTN.Codecs blk NodeId CodecError m
Lazy.ByteString
Lazy.ByteString
Lazy.ByteString
Lazy.ByteString
(AnyMessage (TxSubmission2 (GenTxId blk) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing NodeId))
customNodeToNodeCodecs :: TopLevelConfig blk
-> NodeToNodeVersion
-> Codecs
blk
NodeId
CodecError
m
ByteString
ByteString
ByteString
ByteString
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing NodeId))
customNodeToNodeCodecs TopLevelConfig blk
cfg NodeToNodeVersion
ntnVersion = NTN.Codecs
{ cChainSyncCodec :: Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
CodecError
m
ByteString
cChainSyncCodec =
(DeserialiseFailure -> CodecError)
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
CodecError
m
ByteString
forall (m :: * -> *) failure failure' ps bytes.
Functor m =>
(failure -> failure')
-> Codec ps failure m bytes -> Codec ps failure' m bytes
mapFailureCodec (String -> DeserialiseFailure -> CodecError
CodecBytesFailure String
"ChainSync") (Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
CodecError
m
ByteString)
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
CodecError
m
ByteString
forall a b. (a -> b) -> a -> b
$
Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec (ChainSync (Header blk) (Point blk) (Tip blk)) e m bCS
NTN.cChainSyncCodec Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
binaryProtocolCodecs
, cChainSyncCodecSerialised :: Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
CodecError
m
ByteString
cChainSyncCodecSerialised =
(DeserialiseFailure -> CodecError)
-> Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
-> Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
CodecError
m
ByteString
forall (m :: * -> *) failure failure' ps bytes.
Functor m =>
(failure -> failure')
-> Codec ps failure m bytes -> Codec ps failure' m bytes
mapFailureCodec (String -> DeserialiseFailure -> CodecError
CodecBytesFailure String
"ChainSyncSerialised") (Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
-> Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
CodecError
m
ByteString)
-> Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
-> Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
CodecError
m
ByteString
forall a b. (a -> b) -> a -> b
$
Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
-> Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk)) e m bSCS
NTN.cChainSyncCodecSerialised Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
binaryProtocolCodecs
, cBlockFetchCodec :: Codec (BlockFetch blk (Point blk)) CodecError m ByteString
cBlockFetchCodec =
(DeserialiseFailure -> CodecError)
-> Codec
(BlockFetch blk (Point blk)) DeserialiseFailure m ByteString
-> Codec (BlockFetch blk (Point blk)) CodecError m ByteString
forall (m :: * -> *) failure failure' ps bytes.
Functor m =>
(failure -> failure')
-> Codec ps failure m bytes -> Codec ps failure' m bytes
mapFailureCodec (String -> DeserialiseFailure -> CodecError
CodecBytesFailure String
"BlockFetch") (Codec (BlockFetch blk (Point blk)) DeserialiseFailure m ByteString
-> Codec (BlockFetch blk (Point blk)) CodecError m ByteString)
-> Codec
(BlockFetch blk (Point blk)) DeserialiseFailure m ByteString
-> Codec (BlockFetch blk (Point blk)) CodecError m ByteString
forall a b. (a -> b) -> a -> b
$
Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
-> Codec
(BlockFetch blk (Point blk)) DeserialiseFailure m ByteString
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec (BlockFetch blk (Point blk)) e m bBF
NTN.cBlockFetchCodec Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
binaryProtocolCodecs
, cBlockFetchCodecSerialised :: Codec
(BlockFetch (Serialised blk) (Point blk)) CodecError m ByteString
cBlockFetchCodecSerialised =
(DeserialiseFailure -> CodecError)
-> Codec
(BlockFetch (Serialised blk) (Point blk))
DeserialiseFailure
m
ByteString
-> Codec
(BlockFetch (Serialised blk) (Point blk)) CodecError m ByteString
forall (m :: * -> *) failure failure' ps bytes.
Functor m =>
(failure -> failure')
-> Codec ps failure m bytes -> Codec ps failure' m bytes
mapFailureCodec (String -> DeserialiseFailure -> CodecError
CodecBytesFailure String
"BlockFetchSerialised") (Codec
(BlockFetch (Serialised blk) (Point blk))
DeserialiseFailure
m
ByteString
-> Codec
(BlockFetch (Serialised blk) (Point blk)) CodecError m ByteString)
-> Codec
(BlockFetch (Serialised blk) (Point blk))
DeserialiseFailure
m
ByteString
-> Codec
(BlockFetch (Serialised blk) (Point blk)) CodecError m ByteString
forall a b. (a -> b) -> a -> b
$
Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
-> Codec
(BlockFetch (Serialised blk) (Point blk))
DeserialiseFailure
m
ByteString
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec (BlockFetch (Serialised blk) (Point blk)) e m bSBF
NTN.cBlockFetchCodecSerialised Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
binaryProtocolCodecs
, cTxSubmission2Codec :: Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecError
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
cTxSubmission2Codec =
(CodecFailure -> CodecError)
-> Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecFailure
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
-> Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecError
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
forall (m :: * -> *) failure failure' ps bytes.
Functor m =>
(failure -> failure')
-> Codec ps failure m bytes -> Codec ps failure' m bytes
mapFailureCodec CodecFailure -> CodecError
CodecIdFailure (Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecFailure
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
-> Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecError
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk))))
-> Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecFailure
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
-> Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecError
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
forall a b. (a -> b) -> a -> b
$
Codecs
blk
Any
CodecFailure
m
(AnyMessage (ChainSync (Header blk) (Point blk) (Tip blk)))
(AnyMessage
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk)))
(AnyMessage (BlockFetch blk (Point blk)))
(AnyMessage (BlockFetch (Serialised blk) (Point blk)))
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing Any))
-> Codec
(TxSubmission2 (TxId (GenTx blk)) (GenTx blk))
CodecFailure
m
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec (TxSubmission2 (GenTxId blk) (GenTx blk)) e m bTX
NTN.cTxSubmission2Codec Codecs
blk
Any
CodecFailure
m
(AnyMessage (ChainSync (Header blk) (Point blk) (Tip blk)))
(AnyMessage
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk)))
(AnyMessage (BlockFetch blk (Point blk)))
(AnyMessage (BlockFetch (Serialised blk) (Point blk)))
(AnyMessage (TxSubmission2 (TxId (GenTx blk)) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing Any))
forall (m :: * -> *) blk addr.
Monad m =>
Codecs
blk
addr
CodecFailure
m
(AnyMessage (ChainSync (Header blk) (Point blk) (Tip blk)))
(AnyMessage
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk)))
(AnyMessage (BlockFetch blk (Point blk)))
(AnyMessage (BlockFetch (Serialised blk) (Point blk)))
(AnyMessage (TxSubmission2 (GenTxId blk) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing addr))
NTN.identityCodecs
, cKeepAliveCodec :: Codec KeepAlive CodecError m (AnyMessage KeepAlive)
cKeepAliveCodec =
(CodecFailure -> CodecError)
-> Codec KeepAlive CodecFailure m (AnyMessage KeepAlive)
-> Codec KeepAlive CodecError m (AnyMessage KeepAlive)
forall (m :: * -> *) failure failure' ps bytes.
Functor m =>
(failure -> failure')
-> Codec ps failure m bytes -> Codec ps failure' m bytes
mapFailureCodec CodecFailure -> CodecError
CodecIdFailure (Codec KeepAlive CodecFailure m (AnyMessage KeepAlive)
-> Codec KeepAlive CodecError m (AnyMessage KeepAlive))
-> Codec KeepAlive CodecFailure m (AnyMessage KeepAlive)
-> Codec KeepAlive CodecError m (AnyMessage KeepAlive)
forall a b. (a -> b) -> a -> b
$
Codecs
Any
Any
CodecFailure
m
(AnyMessage (ChainSync (Header Any) (Point Any) (Tip Any)))
(AnyMessage
(ChainSync (SerialisedHeader Any) (Point Any) (Tip Any)))
(AnyMessage (BlockFetch Any (Point Any)))
(AnyMessage (BlockFetch (Serialised Any) (Point Any)))
(AnyMessage (TxSubmission2 (GenTxId Any) (GenTx Any)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing Any))
-> Codec KeepAlive CodecFailure m (AnyMessage KeepAlive)
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec KeepAlive e m bKA
NTN.cKeepAliveCodec Codecs
Any
Any
CodecFailure
m
(AnyMessage (ChainSync (Header Any) (Point Any) (Tip Any)))
(AnyMessage
(ChainSync (SerialisedHeader Any) (Point Any) (Tip Any)))
(AnyMessage (BlockFetch Any (Point Any)))
(AnyMessage (BlockFetch (Serialised Any) (Point Any)))
(AnyMessage (TxSubmission2 (GenTxId Any) (GenTx Any)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing Any))
forall (m :: * -> *) blk addr.
Monad m =>
Codecs
blk
addr
CodecFailure
m
(AnyMessage (ChainSync (Header blk) (Point blk) (Tip blk)))
(AnyMessage
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk)))
(AnyMessage (BlockFetch blk (Point blk)))
(AnyMessage (BlockFetch (Serialised blk) (Point blk)))
(AnyMessage (TxSubmission2 (GenTxId blk) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing addr))
NTN.identityCodecs
, cPeerSharingCodec :: Codec
(PeerSharing NodeId) CodecError m (AnyMessage (PeerSharing NodeId))
cPeerSharingCodec =
(CodecFailure -> CodecError)
-> Codec
(PeerSharing NodeId)
CodecFailure
m
(AnyMessage (PeerSharing NodeId))
-> Codec
(PeerSharing NodeId) CodecError m (AnyMessage (PeerSharing NodeId))
forall (m :: * -> *) failure failure' ps bytes.
Functor m =>
(failure -> failure')
-> Codec ps failure m bytes -> Codec ps failure' m bytes
mapFailureCodec CodecFailure -> CodecError
CodecIdFailure (Codec
(PeerSharing NodeId)
CodecFailure
m
(AnyMessage (PeerSharing NodeId))
-> Codec
(PeerSharing NodeId)
CodecError
m
(AnyMessage (PeerSharing NodeId)))
-> Codec
(PeerSharing NodeId)
CodecFailure
m
(AnyMessage (PeerSharing NodeId))
-> Codec
(PeerSharing NodeId) CodecError m (AnyMessage (PeerSharing NodeId))
forall a b. (a -> b) -> a -> b
$
Codecs
Any
NodeId
CodecFailure
m
(AnyMessage (ChainSync (Header Any) (Point Any) (Tip Any)))
(AnyMessage
(ChainSync (SerialisedHeader Any) (Point Any) (Tip Any)))
(AnyMessage (BlockFetch Any (Point Any)))
(AnyMessage (BlockFetch (Serialised Any) (Point Any)))
(AnyMessage (TxSubmission2 (GenTxId Any) (GenTx Any)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing NodeId))
-> Codec
(PeerSharing NodeId)
CodecFailure
m
(AnyMessage (PeerSharing NodeId))
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec (PeerSharing addr) e m bPS
NTN.cPeerSharingCodec Codecs
Any
NodeId
CodecFailure
m
(AnyMessage (ChainSync (Header Any) (Point Any) (Tip Any)))
(AnyMessage
(ChainSync (SerialisedHeader Any) (Point Any) (Tip Any)))
(AnyMessage (BlockFetch Any (Point Any)))
(AnyMessage (BlockFetch (Serialised Any) (Point Any)))
(AnyMessage (TxSubmission2 (GenTxId Any) (GenTx Any)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing NodeId))
forall (m :: * -> *) blk addr.
Monad m =>
Codecs
blk
addr
CodecFailure
m
(AnyMessage (ChainSync (Header blk) (Point blk) (Tip blk)))
(AnyMessage
(ChainSync (SerialisedHeader blk) (Point blk) (Tip blk)))
(AnyMessage (BlockFetch blk (Point blk)))
(AnyMessage (BlockFetch (Serialised blk) (Point blk)))
(AnyMessage (TxSubmission2 (GenTxId blk) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing addr))
NTN.identityCodecs
}
where
binaryProtocolCodecs :: Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
binaryProtocolCodecs = CodecConfig blk
-> BlockNodeToNodeVersion blk
-> (NodeToNodeVersion -> NodeId -> Encoding)
-> (NodeToNodeVersion -> forall s. Decoder s NodeId)
-> NodeToNodeVersion
-> Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
forall (m :: * -> *) blk addr.
(IOLike m, SerialiseNodeToNodeConstraints blk) =>
CodecConfig blk
-> BlockNodeToNodeVersion blk
-> (NodeToNodeVersion -> addr -> Encoding)
-> (NodeToNodeVersion -> forall s. Decoder s addr)
-> NodeToNodeVersion
-> Codecs
blk
addr
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
NTN.defaultCodecs (TopLevelConfig blk -> CodecConfig blk
forall blk. TopLevelConfig blk -> CodecConfig blk
configCodec TopLevelConfig blk
cfg) BlockNodeToNodeVersion blk
blockVersion ((NodeId -> Encoding) -> NodeToNodeVersion -> NodeId -> Encoding
forall a b. a -> b -> a
const NodeId -> Encoding
encodeNodeId) (Decoder s NodeId -> NodeToNodeVersion -> Decoder s NodeId
forall a b. a -> b -> a
const Decoder s NodeId
forall s. Decoder s NodeId
decodeNodeId) NodeToNodeVersion
ntnVersion
data CodecError
= CodecIdFailure CodecFailure
| CodecBytesFailure
String
DeserialiseFailure
deriving (Int -> CodecError -> ShowS
[CodecError] -> ShowS
CodecError -> String
(Int -> CodecError -> ShowS)
-> (CodecError -> String)
-> ([CodecError] -> ShowS)
-> Show CodecError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodecError -> ShowS
showsPrec :: Int -> CodecError -> ShowS
$cshow :: CodecError -> String
show :: CodecError -> String
$cshowList :: [CodecError] -> ShowS
showList :: [CodecError] -> ShowS
Show, Show CodecError
Typeable CodecError
(Typeable CodecError, Show CodecError) =>
(CodecError -> SomeException)
-> (SomeException -> Maybe CodecError)
-> (CodecError -> String)
-> (CodecError -> Bool)
-> Exception CodecError
SomeException -> Maybe CodecError
CodecError -> Bool
CodecError -> String
CodecError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> (e -> Bool)
-> Exception e
$ctoException :: CodecError -> SomeException
toException :: CodecError -> SomeException
$cfromException :: SomeException -> Maybe CodecError
fromException :: SomeException -> Maybe CodecError
$cdisplayException :: CodecError -> String
displayException :: CodecError -> String
$cbacktraceDesired :: CodecError -> Bool
backtraceDesired :: CodecError -> Bool
Exception)
data RestartCause
= RestartScheduled
| RestartChainSyncTerminated
forkBothEdges ::
(IOLike m, RunNode blk, HasCallStack)
=> ResourceRegistry m
-> OracularClock m
-> Tracer m (SlotNo, MiniProtocolState)
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> Map CoreNodeId (VertexStatusVar m blk)
-> (CoreNodeId, CoreNodeId)
-> m [((CoreNodeId, CoreNodeId), EdgeStatusVar m)]
forkBothEdges :: forall (m :: * -> *) blk.
(IOLike m, RunNode blk, HasCallStack) =>
ResourceRegistry m
-> OracularClock m
-> Tracer m (SlotNo, MiniProtocolState)
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> Map CoreNodeId (VertexStatusVar m blk)
-> (CoreNodeId, CoreNodeId)
-> m [((CoreNodeId, CoreNodeId), EdgeStatusVar m)]
forkBothEdges ResourceRegistry m
sharedRegistry OracularClock m
clock Tracer m (SlotNo, MiniProtocolState)
tr (NodeToNodeVersion, BlockNodeToNodeVersion blk)
version (CodecConfig blk, CalcMessageDelay blk)
cfg Map CoreNodeId (VertexStatusVar m blk)
vertexStatusVars (CoreNodeId
node1, CoreNodeId
node2) = do
let endpoint1 :: (CoreNodeId, VertexStatusVar m blk)
endpoint1 = CoreNodeId -> (CoreNodeId, VertexStatusVar m blk)
mkEndpoint CoreNodeId
node1
endpoint2 :: (CoreNodeId, VertexStatusVar m blk)
endpoint2 = CoreNodeId -> (CoreNodeId, VertexStatusVar m blk)
mkEndpoint CoreNodeId
node2
mkEndpoint :: CoreNodeId -> (CoreNodeId, VertexStatusVar m blk)
mkEndpoint CoreNodeId
node = case CoreNodeId
-> Map CoreNodeId (VertexStatusVar m blk)
-> Maybe (VertexStatusVar m blk)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup CoreNodeId
node Map CoreNodeId (VertexStatusVar m blk)
vertexStatusVars of
Maybe (VertexStatusVar m blk)
Nothing -> String -> (CoreNodeId, VertexStatusVar m blk)
forall a. HasCallStack => String -> a
error (String -> (CoreNodeId, VertexStatusVar m blk))
-> String -> (CoreNodeId, VertexStatusVar m blk)
forall a b. (a -> b) -> a -> b
$ String
"node not found: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ CoreNodeId -> String
forall a. Show a => a -> String
show CoreNodeId
node
Just VertexStatusVar m blk
var -> (CoreNodeId
node, VertexStatusVar m blk
var)
let mkDirEdge :: (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m ((CoreNodeId, CoreNodeId), StrictTVar m EdgeStatus)
mkDirEdge (CoreNodeId, VertexStatusVar m blk)
e1 (CoreNodeId, VertexStatusVar m blk)
e2 = do
v <- EdgeStatus -> m (StrictTVar m EdgeStatus)
forall (m :: * -> *) a. MonadSTM m => a -> m (StrictTVar m a)
uncheckedNewTVarM EdgeStatus
EDown
let label = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[String
"directed-edge-", CoreNodeId -> String
forall a. Condense a => a -> String
condense ((CoreNodeId, VertexStatusVar m blk) -> CoreNodeId
forall a b. (a, b) -> a
fst (CoreNodeId, VertexStatusVar m blk)
e1), String
"-", CoreNodeId -> String
forall a. Condense a => a -> String
condense ((CoreNodeId, VertexStatusVar m blk) -> CoreNodeId
forall a b. (a, b) -> a
fst (CoreNodeId, VertexStatusVar m blk)
e2)]
void $ forkLinkedThread sharedRegistry label $ do
directedEdge sharedRegistry tr version cfg clock v e1 e2
pure ((fst e1, fst e2), v)
ev12 <- (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m ((CoreNodeId, CoreNodeId), StrictTVar m EdgeStatus)
mkDirEdge (CoreNodeId, VertexStatusVar m blk)
endpoint1 (CoreNodeId, VertexStatusVar m blk)
endpoint2
ev21 <- mkDirEdge endpoint2 endpoint1
pure [ev12, ev21]
directedEdge ::
forall m blk. (IOLike m, RunNode blk)
=> ResourceRegistry m
-> Tracer m (SlotNo, MiniProtocolState)
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> OracularClock m
-> EdgeStatusVar m
-> (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m ()
directedEdge :: forall (m :: * -> *) blk.
(IOLike m, RunNode blk) =>
ResourceRegistry m
-> Tracer m (SlotNo, MiniProtocolState)
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> OracularClock m
-> EdgeStatusVar m
-> (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m ()
directedEdge ResourceRegistry m
registry Tracer m (SlotNo, MiniProtocolState)
tr (NodeToNodeVersion, BlockNodeToNodeVersion blk)
version (CodecConfig blk, CalcMessageDelay blk)
cfg OracularClock m
clock EdgeStatusVar m
edgeStatusVar (CoreNodeId, VertexStatusVar m blk)
client (CoreNodeId, VertexStatusVar m blk)
server =
m ()
loop
where
loop :: m ()
loop = do
restart <- ResourceRegistry m
-> OracularClock m
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> EdgeStatusVar m
-> (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m RestartCause
forall (m :: * -> *) blk.
(IOLike m, RunNode blk) =>
ResourceRegistry m
-> OracularClock m
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> EdgeStatusVar m
-> (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m RestartCause
directedEdgeInner ResourceRegistry m
registry OracularClock m
clock (NodeToNodeVersion, BlockNodeToNodeVersion blk)
version (CodecConfig blk, CalcMessageDelay blk)
cfg EdgeStatusVar m
edgeStatusVar (CoreNodeId, VertexStatusVar m blk)
client (CoreNodeId, VertexStatusVar m blk)
server
m RestartCause
-> (SomeException -> m RestartCause) -> m RestartCause
forall e a. Exception e => m a -> (e -> m a) -> m a
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`catch` SomeException -> m RestartCause
forall a. SomeException -> m a
hUnexpected
atomically $ writeTVar edgeStatusVar EDown
case restart of
RestartCause
RestartScheduled -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
RestartCause
RestartChainSyncTerminated -> do
s <- OracularClock m -> m SlotNo
forall (m :: * -> *). OracularClock m -> m SlotNo
OracularClock.getCurrentSlot OracularClock m
clock
let s' = SlotNo -> SlotNo
forall a. Enum a => a -> a
succ SlotNo
s
traceWith tr (s, MiniProtocolDelayed)
void $ OracularClock.blockUntilSlot clock s'
traceWith tr (s', MiniProtocolRestarting)
loop
where
hUnexpected :: forall a. SomeException -> m a
hUnexpected :: forall a. SomeException -> m a
hUnexpected e :: SomeException
e@(Exn.SomeException e
e') = case SomeException -> Maybe AsyncException
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e of
Just (AsyncException
_ :: Exn.AsyncException) -> SomeException -> m a
forall e a. Exception e => e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO SomeException
e
Maybe AsyncException
Nothing -> case SomeException -> Maybe SomeAsyncException
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e of
Just (SomeAsyncException
_ :: Exn.SomeAsyncException) -> SomeException -> m a
forall e a. Exception e => e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO SomeException
e
Maybe SomeAsyncException
Nothing -> MiniProtocolFatalException -> m a
forall e a. Exception e => e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO MiniProtocolFatalException
{ mpfeType :: TypeRep
mpfeType = e -> TypeRep
forall a. Typeable a => a -> TypeRep
Typeable.typeOf e
e'
, mpfeExn :: SomeException
mpfeExn = SomeException
e
, mpfeClient :: CoreNodeId
mpfeClient = (CoreNodeId, VertexStatusVar m blk) -> CoreNodeId
forall a b. (a, b) -> a
fst (CoreNodeId, VertexStatusVar m blk)
client
, mpfeServer :: CoreNodeId
mpfeServer = (CoreNodeId, VertexStatusVar m blk) -> CoreNodeId
forall a b. (a, b) -> a
fst (CoreNodeId, VertexStatusVar m blk)
server
}
directedEdgeInner ::
forall m blk. (IOLike m, RunNode blk)
=> ResourceRegistry m
-> OracularClock m
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> EdgeStatusVar m
-> (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m RestartCause
directedEdgeInner :: forall (m :: * -> *) blk.
(IOLike m, RunNode blk) =>
ResourceRegistry m
-> OracularClock m
-> (NodeToNodeVersion, BlockNodeToNodeVersion blk)
-> (CodecConfig blk, CalcMessageDelay blk)
-> EdgeStatusVar m
-> (CoreNodeId, VertexStatusVar m blk)
-> (CoreNodeId, VertexStatusVar m blk)
-> m RestartCause
directedEdgeInner ResourceRegistry m
registry OracularClock m
clock (NodeToNodeVersion
version, BlockNodeToNodeVersion blk
blockVersion) (CodecConfig blk
cfg, CalcMessageDelay blk
calcMessageDelay) EdgeStatusVar m
edgeStatusVar
(CoreNodeId
node1, VertexStatusVar m blk
vertexStatusVar1) (CoreNodeId
node2, VertexStatusVar m blk
vertexStatusVar2) = do
(LimitedApp app1, LimitedApp app2) <- STM m (LimitedApp m NodeId blk, LimitedApp m NodeId blk)
-> m (LimitedApp m NodeId blk, LimitedApp m NodeId blk)
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m (LimitedApp m NodeId blk, LimitedApp m NodeId blk)
-> m (LimitedApp m NodeId blk, LimitedApp m NodeId blk))
-> STM m (LimitedApp m NodeId blk, LimitedApp m NodeId blk)
-> m (LimitedApp m NodeId blk, LimitedApp m NodeId blk)
forall a b. (a -> b) -> a -> b
$ do
(,) (LimitedApp m NodeId blk
-> LimitedApp m NodeId blk
-> (LimitedApp m NodeId blk, LimitedApp m NodeId blk))
-> STM m (LimitedApp m NodeId blk)
-> STM
m
(LimitedApp m NodeId blk
-> (LimitedApp m NodeId blk, LimitedApp m NodeId blk))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> VertexStatusVar m blk -> STM m (LimitedApp m NodeId blk)
forall {m :: * -> *} {m :: * -> *} {blk}.
MonadSTM m =>
StrictTVar m (VertexStatus m blk)
-> STM m (LimitedApp m NodeId blk)
getApp VertexStatusVar m blk
vertexStatusVar1 STM
m
(LimitedApp m NodeId blk
-> (LimitedApp m NodeId blk, LimitedApp m NodeId blk))
-> STM m (LimitedApp m NodeId blk)
-> STM m (LimitedApp m NodeId blk, LimitedApp m NodeId blk)
forall a b. STM m (a -> b) -> STM m a -> STM m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> VertexStatusVar m blk -> STM m (LimitedApp m NodeId blk)
forall {m :: * -> *} {m :: * -> *} {blk}.
MonadSTM m =>
StrictTVar m (VertexStatus m blk)
-> STM m (LimitedApp m NodeId blk)
getApp VertexStatusVar m blk
vertexStatusVar2
atomically $ writeTVar edgeStatusVar EUp
let miniProtocol ::
String
-> (String -> a -> RestartCause)
-> (String -> b -> RestartCause)
-> ( LimitedApp' m NodeId blk
-> NodeToNodeVersion
-> ExpandedInitiatorContext NodeId m
-> Channel m msg
-> m (a, trailingBytes)
)
-> ( LimitedApp' m NodeId blk
-> NodeToNodeVersion
-> ResponderContext NodeId
-> Channel m msg
-> m (b, trailingBytes)
)
-> (msg -> m ())
-> m (m RestartCause, m RestartCause)
miniProtocol String
proto String -> a -> RestartCause
retClient String -> b -> RestartCause
retServer LimitedApp' m NodeId blk
-> NodeToNodeVersion
-> ExpandedInitiatorContext NodeId m
-> Channel m msg
-> m (a, trailingBytes)
client LimitedApp' m NodeId blk
-> NodeToNodeVersion
-> ResponderContext NodeId
-> Channel m msg
-> m (b, trailingBytes)
server msg -> m ()
middle = do
(chan, dualChan) <-
ResourceRegistry m
-> (CoreNodeId, CoreNodeId, String)
-> (msg -> m ())
-> m (Channel m msg, Channel m msg)
forall (m :: * -> *) a.
IOLike m =>
ResourceRegistry m
-> (CoreNodeId, CoreNodeId, String)
-> (a -> m ())
-> m (Channel m a, Channel m a)
createConnectedChannelsWithDelay ResourceRegistry m
registry (CoreNodeId
node1, CoreNodeId
node2, String
proto) msg -> m ()
middle
pure
( (retClient (proto <> ".client") . fst) <$> client app1 version initiatorCtx chan
, (retServer (proto <> ".server") . fst) <$> server app2 version responderCtx dualChan
)
where
initiatorCtx :: ExpandedInitiatorContext NodeId m
initiatorCtx = ExpandedInitiatorContext {
eicConnectionId :: ConnectionId NodeId
eicConnectionId = NodeId -> NodeId -> ConnectionId NodeId
forall addr. addr -> addr -> ConnectionId addr
ConnectionId (CoreNodeId -> NodeId
fromCoreNodeId CoreNodeId
node1) (CoreNodeId -> NodeId
fromCoreNodeId CoreNodeId
node2),
eicControlMessage :: ControlMessageSTM m
eicControlMessage = ControlMessage -> ControlMessageSTM m
forall a. a -> STM m a
forall (m :: * -> *) a. Monad m => a -> m a
return ControlMessage
Continue,
eicIsBigLedgerPeer :: IsBigLedgerPeer
eicIsBigLedgerPeer = IsBigLedgerPeer
IsNotBigLedgerPeer
}
responderCtx :: ResponderContext NodeId
responderCtx = ResponderContext {
rcConnectionId :: ConnectionId NodeId
rcConnectionId = NodeId -> NodeId -> ConnectionId NodeId
forall addr. addr -> addr -> ConnectionId addr
ConnectionId (CoreNodeId -> NodeId
fromCoreNodeId CoreNodeId
node1) (CoreNodeId -> NodeId
fromCoreNodeId CoreNodeId
node2)
}
(>>= withAsyncsWaitAny) $
fmap flattenPairs $
sequence $
pure (watcher vertexStatusVar1, watcher vertexStatusVar2)
NE.:|
[ miniProtocol "ChainSync"
(\String
_s NodeToNodeInitiatorResult
_ -> RestartCause
RestartChainSyncTerminated)
(\String
_s () -> RestartCause
RestartChainSyncTerminated)
NTN.aChainSyncClient
NTN.aChainSyncServer
chainSyncMiddle
, miniProtocol "BlockFetch"
neverReturns
neverReturns
NTN.aBlockFetchClient
NTN.aBlockFetchServer
(\ByteString
_ -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
, miniProtocol "TxSubmission"
neverReturns
neverReturns
NTN.aTxSubmission2Client
NTN.aTxSubmission2Server
(\AnyMessage (TxSubmission2 (GenTxId blk) (GenTx blk))
_ -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
, miniProtocol "KeepAlive"
neverReturns
neverReturns
NTN.aKeepAliveClient
NTN.aKeepAliveServer
(\AnyMessage KeepAlive
_ -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
]
where
getApp :: StrictTVar m (VertexStatus m blk)
-> STM m (LimitedApp m NodeId blk)
getApp StrictTVar m (VertexStatus m blk)
v = StrictTVar m (VertexStatus m blk) -> STM m (VertexStatus m blk)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar StrictTVar m (VertexStatus m blk)
v STM m (VertexStatus m blk)
-> (VertexStatus m blk -> STM m (LimitedApp m NodeId blk))
-> STM m (LimitedApp m NodeId blk)
forall a b. STM m a -> (a -> STM m b) -> STM m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
VUp NodeKernel m NodeId Void blk
_ LimitedApp m NodeId blk
app -> LimitedApp m NodeId blk -> STM m (LimitedApp m NodeId blk)
forall a. a -> STM m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LimitedApp m NodeId blk
app
VertexStatus m blk
_ -> STM m (LimitedApp m NodeId blk)
forall a. STM m a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
flattenPairs :: forall a. NE.NonEmpty (a, a) -> NE.NonEmpty a
flattenPairs :: forall a. NonEmpty (a, a) -> NonEmpty a
flattenPairs = (NonEmpty a -> NonEmpty a -> NonEmpty a)
-> (NonEmpty a, NonEmpty a) -> NonEmpty a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry NonEmpty a -> NonEmpty a -> NonEmpty a
forall a. Semigroup a => a -> a -> a
(<>) ((NonEmpty a, NonEmpty a) -> NonEmpty a)
-> (NonEmpty (a, a) -> (NonEmpty a, NonEmpty a))
-> NonEmpty (a, a)
-> NonEmpty a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (a, a) -> (NonEmpty a, NonEmpty a)
forall (f :: * -> *) a b. Functor f => f (a, b) -> (f a, f b)
neUnzip
neverReturns :: forall x void. String -> x -> void
neverReturns :: forall x void. String -> x -> void
neverReturns String
s !x
_ = String -> void
forall a. HasCallStack => String -> a
error (String -> void) -> String -> void
forall a b. (a -> b) -> a -> b
$ String
s String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" never returns!"
watcher :: VertexStatusVar m blk -> m RestartCause
watcher :: VertexStatusVar m blk -> m RestartCause
watcher VertexStatusVar m blk
v = do
STM m RestartCause -> m RestartCause
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m RestartCause -> m RestartCause)
-> STM m RestartCause -> m RestartCause
forall a b. (a -> b) -> a -> b
$ VertexStatusVar m blk -> STM m (VertexStatus m blk)
forall (m :: * -> *) a. MonadSTM m => StrictTVar m a -> STM m a
readTVar VertexStatusVar m blk
v STM m (VertexStatus m blk)
-> (VertexStatus m blk -> STM m RestartCause) -> STM m RestartCause
forall a b. STM m a -> (a -> STM m b) -> STM m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
VertexStatus m blk
VFalling -> RestartCause -> STM m RestartCause
forall a. a -> STM m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure RestartCause
RestartScheduled
VertexStatus m blk
_ -> STM m RestartCause
forall a. STM m a
forall (m :: * -> *) a. MonadSTM m => STM m a
retry
chainSyncMiddle :: Lazy.ByteString -> m ()
chainSyncMiddle :: ByteString -> m ()
chainSyncMiddle ByteString
bs = do
let tok :: SingChainSync ('StNext 'StMustReply)
tok = SingNextKind 'StMustReply -> SingChainSync ('StNext 'StMustReply)
forall {header} {point} {tip} (k1 :: StNextKind).
SingNextKind k1 -> SingChainSync ('StNext k1)
CS.SingNext SingNextKind 'StMustReply
CS.SingMustReply
decodeStep :: Codec.DecodeStep
Lazy.ByteString DeserialiseFailure m
(Codec.SomeMessage ('CS.StNext 'CS.StMustReply))
<- Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
-> forall (st :: ChainSync (Header blk) (Point blk) (Tip blk)).
ActiveState st =>
StateToken st
-> m (DecodeStep ByteString DeserialiseFailure m (SomeMessage st))
forall ps failure (m :: * -> *) bytes.
Codec ps failure m bytes
-> forall (st :: ps).
ActiveState st =>
StateToken st -> m (DecodeStep bytes failure m (SomeMessage st))
Codec.decode Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
codec SingChainSync ('StNext 'StMustReply)
StateToken ('StNext 'StMustReply)
forall {header} {point} {tip}. SingChainSync ('StNext 'StMustReply)
tok
Codec.runDecoder [bs] decodeStep >>= \case
Right (Codec.SomeMessage (CS.MsgRollForward Header blk
hdr Tip blk
_tip)) -> do
s <- OracularClock m -> m SlotNo
forall (m :: * -> *). OracularClock m -> m SlotNo
OracularClock.getCurrentSlot OracularClock m
clock
let NumSlots d = f (node1, node2) s hdr
where
CalcMessageDelay f = calcMessageDelay
void $ OracularClock.blockUntilSlot clock $ blockSlot hdr + SlotNo d
Either DeserialiseFailure (SomeMessage ('StNext 'StMustReply))
_ -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
where
codec :: Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
codec =
Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
forall blk addr e (m :: * -> *) bCS bSCS bBF bSBF bTX bKA bPS.
Codecs blk addr e m bCS bSCS bBF bSBF bTX bKA bPS
-> Codec (ChainSync (Header blk) (Point blk) (Tip blk)) e m bCS
NTN.cChainSyncCodec (Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString)
-> Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
-> Codec
(ChainSync (Header blk) (Point blk) (Tip blk))
DeserialiseFailure
m
ByteString
forall a b. (a -> b) -> a -> b
$ CodecConfig blk
-> BlockNodeToNodeVersion blk
-> (NodeToNodeVersion -> NodeId -> Encoding)
-> (NodeToNodeVersion -> forall s. Decoder s NodeId)
-> NodeToNodeVersion
-> Codecs
blk
NodeId
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
forall (m :: * -> *) blk addr.
(IOLike m, SerialiseNodeToNodeConstraints blk) =>
CodecConfig blk
-> BlockNodeToNodeVersion blk
-> (NodeToNodeVersion -> addr -> Encoding)
-> (NodeToNodeVersion -> forall s. Decoder s addr)
-> NodeToNodeVersion
-> Codecs
blk
addr
DeserialiseFailure
m
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
ByteString
NTN.defaultCodecs CodecConfig blk
cfg BlockNodeToNodeVersion blk
blockVersion ((NodeId -> Encoding) -> NodeToNodeVersion -> NodeId -> Encoding
forall a b. a -> b -> a
const NodeId -> Encoding
encodeNodeId) (Decoder s NodeId -> NodeToNodeVersion -> Decoder s NodeId
forall a b. a -> b -> a
const Decoder s NodeId
forall s. Decoder s NodeId
decodeNodeId) NodeToNodeVersion
version
createConnectedChannelsWithDelay ::
IOLike m
=> ResourceRegistry m
-> (CoreNodeId, CoreNodeId, String)
-> (a -> m ())
-> m (Channel m a, Channel m a)
createConnectedChannelsWithDelay :: forall (m :: * -> *) a.
IOLike m =>
ResourceRegistry m
-> (CoreNodeId, CoreNodeId, String)
-> (a -> m ())
-> m (Channel m a, Channel m a)
createConnectedChannelsWithDelay ResourceRegistry m
registry (CoreNodeId
client, CoreNodeId
server, String
proto) a -> m ()
middle = do
qA <- STM m (TQueue m a) -> m (TQueue m a)
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m (TQueue m a) -> m (TQueue m a))
-> STM m (TQueue m a) -> m (TQueue m a)
forall a b. (a -> b) -> a -> b
$ STM m (TQueue m a)
forall a. STM m (TQueue m a)
forall (m :: * -> *) a. MonadSTM m => STM m (TQueue m a)
MonadSTM.newTQueue
bA <- atomically $ MonadSTM.newEmptyTMVar
spawn (client, server) qA bA
qB <- atomically $ MonadSTM.newTQueue
bB <- atomically $ MonadSTM.newEmptyTMVar
spawn (server, client) qB bB
return (chan qA bB, chan qB bA)
where
spawn :: (CoreNodeId, CoreNodeId) -> TQueue m a -> TMVar m a -> m ()
spawn (CoreNodeId
cid1, CoreNodeId
cid2) TQueue m a
q TMVar m a
b = do
let label :: String
label =
String
"delaying thread for " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
proto String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
CoreNodeId -> String
forall a. Show a => a -> String
show CoreNodeId
cid1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" to " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> CoreNodeId -> String
forall a. Show a => a -> String
show CoreNodeId
cid2
m (Thread m Any) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (Thread m Any) -> m ()) -> m (Thread m Any) -> m ()
forall a b. (a -> b) -> a -> b
$ ResourceRegistry m -> String -> m Any -> m (Thread m Any)
forall (m :: * -> *) a.
(MonadAsync m, MonadFork m, MonadMask m, HasCallStack) =>
ResourceRegistry m -> String -> m a -> m (Thread m a)
forkLinkedThread ResourceRegistry m
registry String
label (m Any -> m (Thread m Any)) -> m Any -> m (Thread m Any)
forall a b. (a -> b) -> a -> b
$ m () -> m Any
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (m () -> m Any) -> m () -> m Any
forall a b. (a -> b) -> a -> b
$ do
x <- STM m a -> m a
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m a -> m a) -> STM m a -> m a
forall a b. (a -> b) -> a -> b
$ TQueue m a -> STM m a
forall a. TQueue m a -> STM m a
forall (m :: * -> *) a. MonadSTM m => TQueue m a -> STM m a
MonadSTM.readTQueue TQueue m a
q
middle x
atomically $ MonadSTM.putTMVar b x
chan :: TQueue m a -> TMVar m a -> Channel m a
chan TQueue m a
q TMVar m a
b = Channel
{ recv :: m (Maybe a)
recv = (a -> Maybe a) -> m a -> m (Maybe a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (m a -> m (Maybe a)) -> m a -> m (Maybe a)
forall a b. (a -> b) -> a -> b
$ STM m a -> m a
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m a -> m a) -> STM m a -> m a
forall a b. (a -> b) -> a -> b
$ TMVar m a -> STM m a
forall a. TMVar m a -> STM m a
forall (m :: * -> *) a. MonadSTM m => TMVar m a -> STM m a
MonadSTM.takeTMVar TMVar m a
b
, send :: a -> m ()
send = STM m () -> m ()
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m () -> m ()) -> (a -> STM m ()) -> a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TQueue m a -> a -> STM m ()
forall a. TQueue m a -> a -> STM m ()
forall (m :: * -> *) a. MonadSTM m => TQueue m a -> a -> STM m ()
MonadSTM.writeTQueue TQueue m a
q
}
data NodeInfo blk db ev = NodeInfo
{ forall blk db (ev :: * -> *).
NodeInfo blk db ev -> NodeEvents blk ev
nodeInfoEvents :: NodeEvents blk ev
, forall blk db (ev :: * -> *). NodeInfo blk db ev -> NodeDBs db
nodeInfoDBs :: NodeDBs db
}
data NodeEvents blk ev = NodeEvents
{ forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (SlotNo, RealPoint blk, BlockNo)
nodeEventsAdds :: ev (SlotNo, RealPoint blk, BlockNo)
, forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (TraceForgeEvent blk)
nodeEventsForges :: ev (TraceForgeEvent blk)
, :: ev (SlotNo, RealPoint blk, BlockNo)
, forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (RealPoint blk, ExtValidationError blk)
nodeEventsInvalids :: ev (RealPoint blk, ExtValidationError blk)
, forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (SlotNo, RealPoint blk, BlockNo)
nodeEventsSelects :: ev (SlotNo, RealPoint blk, BlockNo)
, forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (SlotNo, WithOrigin BlockNo)
nodeEventsTipBlockNos :: ev (SlotNo, WithOrigin BlockNo)
, forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (LedgerUpdate blk)
nodeEventsUpdates :: ev (LedgerUpdate blk)
, forall blk (ev :: * -> *).
NodeEvents blk ev -> ev (TracePipeliningEvent blk)
nodeEventsPipelining :: ev (ChainDB.TracePipeliningEvent blk)
}
newNodeInfo ::
forall blk m.
IOLike m
=> m ( NodeInfo blk (StrictTMVar m MockFS) (Tracer m)
, m (NodeInfo blk MockFS [])
)
newNodeInfo :: forall blk (m :: * -> *).
IOLike m =>
m (NodeInfo blk (StrictTMVar m MockFS) (Tracer m),
m (NodeInfo blk MockFS []))
newNodeInfo = do
(nodeInfoEvents, readEvents) <- do
(t1, m1) <- m (Tracer m (SlotNo, RealPoint blk, BlockNo),
m [(SlotNo, RealPoint blk, BlockNo)])
forall (m :: * -> *) ev. MonadSTM m => m (Tracer m ev, m [ev])
recordingTracerTVar
(t2, m2) <- recordingTracerTVar
(t3, m3) <- recordingTracerTVar
(t4, m4) <- recordingTracerTVar
(t5, m5) <- recordingTracerTVar
(t6, m6) <- recordingTracerTVar
(t7, m7) <- recordingTracerTVar
(t8, m8) <- recordingTracerTVar
pure
( NodeEvents t1 t2 t3 t4 t5 t6 t7 t8
, NodeEvents <$> m1 <*> m2 <*> m3 <*> m4 <*> m5 <*> m6 <*> m7 <*> m8
)
(nodeInfoDBs, readDBs) <- do
let mk :: m (StrictTMVar m MockFS, STM m MockFS)
mk = do
v <- STM m (StrictTMVar m MockFS) -> m (StrictTMVar m MockFS)
forall a. HasCallStack => STM m a -> m a
forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
atomically (STM m (StrictTMVar m MockFS) -> m (StrictTMVar m MockFS))
-> STM m (StrictTMVar m MockFS) -> m (StrictTMVar m MockFS)
forall a b. (a -> b) -> a -> b
$ MockFS -> STM m (StrictTMVar m MockFS)
forall (m :: * -> *) a. MonadSTM m => a -> STM m (StrictTMVar m a)
newTMVar MockFS
Mock.empty
pure (v, readTMVar v)
(v1, m1) <- mk
(v2, m2) <- mk
(v3, m3) <- mk
(v4, m4) <- mk
pure
( NodeDBs v1 v2 v3 v4
, NodeDBs <$> m1 <*> m2 <*> m3 <*> m4
)
pure
( NodeInfo{nodeInfoEvents, nodeInfoDBs }
, NodeInfo <$> readEvents <*> atomically readDBs
)
data NodeOutput blk = NodeOutput
{ forall blk.
NodeOutput blk -> Map SlotNo (Set (RealPoint blk, BlockNo))
nodeOutputAdds :: Map SlotNo (Set (RealPoint blk, BlockNo))
, forall blk. NodeOutput blk -> Map SlotNo [CannotForge blk]
nodeOutputCannotForges :: Map SlotNo [CannotForge blk]
, forall blk. NodeOutput blk -> Chain blk
nodeOutputFinalChain :: Chain blk
, forall blk. NodeOutput blk -> LedgerState blk EmptyMK
nodeOutputFinalLedger :: LedgerState blk EmptyMK
, forall blk. NodeOutput blk -> Map SlotNo blk
nodeOutputForges :: Map SlotNo blk
, :: Map SlotNo [(RealPoint blk, BlockNo)]
, forall blk.
NodeOutput blk -> Map (RealPoint blk) [ExtValidationError blk]
nodeOutputInvalids :: Map (RealPoint blk) [ExtValidationError blk]
, forall blk. NodeOutput blk -> NodeDBs MockFS
nodeOutputNodeDBs :: NodeDBs MockFS
, forall blk. NodeOutput blk -> Map SlotNo [(RealPoint blk, BlockNo)]
nodeOutputSelects :: Map SlotNo [(RealPoint blk, BlockNo)]
, forall blk. NodeOutput blk -> [LedgerUpdate blk]
nodeOutputUpdates :: [LedgerUpdate blk]
, forall blk. NodeOutput blk -> [TracePipeliningEvent blk]
nodePipeliningEvents :: [ChainDB.TracePipeliningEvent blk]
}
data TestOutput blk = TestOutput
{ forall blk. TestOutput blk -> Map NodeId (NodeOutput blk)
testOutputNodes :: Map NodeId (NodeOutput blk)
, forall blk.
TestOutput blk -> Map SlotNo (Map NodeId (WithOrigin BlockNo))
testOutputTipBlockNos :: Map SlotNo (Map NodeId (WithOrigin BlockNo))
}
mkTestOutput ::
forall m blk. (IOLike m, HasHeader blk)
=> [( CoreNodeId
, m (NodeInfo blk MockFS [])
, Chain blk
, LedgerState blk EmptyMK
)]
-> m (TestOutput blk)
mkTestOutput :: forall (m :: * -> *) blk.
(IOLike m, HasHeader blk) =>
[(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)]
-> m (TestOutput blk)
mkTestOutput [(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)]
vertexInfos = do
(nodeOutputs', tipBlockNos') <- ([(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))]
-> ([Map NodeId (NodeOutput blk)],
[Map SlotNo (Map NodeId (WithOrigin BlockNo))]))
-> m [(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))]
-> m ([Map NodeId (NodeOutput blk)],
[Map SlotNo (Map NodeId (WithOrigin BlockNo))])
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))]
-> ([Map NodeId (NodeOutput blk)],
[Map SlotNo (Map NodeId (WithOrigin BlockNo))])
forall a b. [(a, b)] -> ([a], [b])
unzip (m [(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))]
-> m ([Map NodeId (NodeOutput blk)],
[Map SlotNo (Map NodeId (WithOrigin BlockNo))]))
-> m [(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))]
-> m ([Map NodeId (NodeOutput blk)],
[Map SlotNo (Map NodeId (WithOrigin BlockNo))])
forall a b. (a -> b) -> a -> b
$ [(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)]
-> ((CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)
-> m (Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo))))
-> m [(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)]
vertexInfos (((CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)
-> m (Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo))))
-> m [(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))])
-> ((CoreNodeId, m (NodeInfo blk MockFS []), Chain blk,
LedgerState blk EmptyMK)
-> m (Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo))))
-> m [(Map NodeId (NodeOutput blk),
Map SlotNo (Map NodeId (WithOrigin BlockNo)))]
forall a b. (a -> b) -> a -> b
$
\(CoreNodeId
cid, m (NodeInfo blk MockFS [])
readNodeInfo, Chain blk
ch, LedgerState blk EmptyMK
ldgr) -> do
let nid :: NodeId
nid = CoreNodeId -> NodeId
fromCoreNodeId CoreNodeId
cid
nodeInfo <- m (NodeInfo blk MockFS [])
readNodeInfo
let NodeInfo
{ nodeInfoEvents
, nodeInfoDBs
} = nodeInfo
let NodeEvents
{ nodeEventsAdds
, nodeEventsForges
, nodeEventsHeaderAdds
, nodeEventsInvalids
, nodeEventsSelects
, nodeEventsTipBlockNos
, nodeEventsUpdates
, nodeEventsPipelining
} = nodeInfoEvents
let nodeOutput = NodeOutput
{ nodeOutputAdds :: Map SlotNo (Set (RealPoint blk, BlockNo))
nodeOutputAdds =
(Set (RealPoint blk, BlockNo)
-> Set (RealPoint blk, BlockNo) -> Set (RealPoint blk, BlockNo))
-> [(SlotNo, Set (RealPoint blk, BlockNo))]
-> Map SlotNo (Set (RealPoint blk, BlockNo))
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith Set (RealPoint blk, BlockNo)
-> Set (RealPoint blk, BlockNo) -> Set (RealPoint blk, BlockNo)
forall a. Ord a => Set a -> Set a -> Set a
Set.union ([(SlotNo, Set (RealPoint blk, BlockNo))]
-> Map SlotNo (Set (RealPoint blk, BlockNo)))
-> [(SlotNo, Set (RealPoint blk, BlockNo))]
-> Map SlotNo (Set (RealPoint blk, BlockNo))
forall a b. (a -> b) -> a -> b
$
[ (SlotNo
s, (RealPoint blk, BlockNo) -> Set (RealPoint blk, BlockNo)
forall a. a -> Set a
Set.singleton (RealPoint blk
p, BlockNo
bno)) | (SlotNo
s, RealPoint blk
p, BlockNo
bno) <- [(SlotNo, RealPoint blk, BlockNo)]
nodeEventsAdds ]
, nodeOutputCannotForges :: Map SlotNo [CannotForge blk]
nodeOutputCannotForges =
([CannotForge blk] -> [CannotForge blk] -> [CannotForge blk])
-> [(SlotNo, [CannotForge blk])] -> Map SlotNo [CannotForge blk]
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith (([CannotForge blk] -> [CannotForge blk] -> [CannotForge blk])
-> [CannotForge blk] -> [CannotForge blk] -> [CannotForge blk]
forall a b c. (a -> b -> c) -> b -> a -> c
flip [CannotForge blk] -> [CannotForge blk] -> [CannotForge blk]
forall a. [a] -> [a] -> [a]
(++)) ([(SlotNo, [CannotForge blk])] -> Map SlotNo [CannotForge blk])
-> [(SlotNo, [CannotForge blk])] -> Map SlotNo [CannotForge blk]
forall a b. (a -> b) -> a -> b
$
[ (SlotNo
s, [CannotForge blk
err]) | TraceNodeCannotForge SlotNo
s CannotForge blk
err <- [TraceForgeEvent blk]
nodeEventsForges ]
, nodeOutputFinalChain :: Chain blk
nodeOutputFinalChain = Chain blk
ch
, nodeOutputFinalLedger :: LedgerState blk EmptyMK
nodeOutputFinalLedger = LedgerState blk EmptyMK
ldgr
, nodeOutputForges :: Map SlotNo blk
nodeOutputForges =
[(SlotNo, blk)] -> Map SlotNo blk
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(SlotNo, blk)] -> Map SlotNo blk)
-> [(SlotNo, blk)] -> Map SlotNo blk
forall a b. (a -> b) -> a -> b
$
[ (SlotNo
s, blk
b) | TraceForgedBlock SlotNo
s Point blk
_ blk
b MempoolSize
_ <- [TraceForgeEvent blk]
nodeEventsForges ]
, nodeOutputHeaderAdds :: Map SlotNo [(RealPoint blk, BlockNo)]
nodeOutputHeaderAdds =
([(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)] -> [(RealPoint blk, BlockNo)])
-> [(SlotNo, [(RealPoint blk, BlockNo)])]
-> Map SlotNo [(RealPoint blk, BlockNo)]
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith (([(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)] -> [(RealPoint blk, BlockNo)])
-> [(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)]
forall a b c. (a -> b -> c) -> b -> a -> c
flip [(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)] -> [(RealPoint blk, BlockNo)]
forall a. [a] -> [a] -> [a]
(++)) ([(SlotNo, [(RealPoint blk, BlockNo)])]
-> Map SlotNo [(RealPoint blk, BlockNo)])
-> [(SlotNo, [(RealPoint blk, BlockNo)])]
-> Map SlotNo [(RealPoint blk, BlockNo)]
forall a b. (a -> b) -> a -> b
$
[ (SlotNo
s, [(RealPoint blk
p, BlockNo
bno)])
| (SlotNo
s, RealPoint blk
p, BlockNo
bno) <- [(SlotNo, RealPoint blk, BlockNo)]
nodeEventsHeaderAdds
]
, nodeOutputSelects :: Map SlotNo [(RealPoint blk, BlockNo)]
nodeOutputSelects =
([(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)] -> [(RealPoint blk, BlockNo)])
-> [(SlotNo, [(RealPoint blk, BlockNo)])]
-> Map SlotNo [(RealPoint blk, BlockNo)]
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith (([(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)] -> [(RealPoint blk, BlockNo)])
-> [(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)]
forall a b c. (a -> b -> c) -> b -> a -> c
flip [(RealPoint blk, BlockNo)]
-> [(RealPoint blk, BlockNo)] -> [(RealPoint blk, BlockNo)]
forall a. [a] -> [a] -> [a]
(++)) ([(SlotNo, [(RealPoint blk, BlockNo)])]
-> Map SlotNo [(RealPoint blk, BlockNo)])
-> [(SlotNo, [(RealPoint blk, BlockNo)])]
-> Map SlotNo [(RealPoint blk, BlockNo)]
forall a b. (a -> b) -> a -> b
$
[ (SlotNo
s, [(RealPoint blk
p, BlockNo
bno)])
| (SlotNo
s, RealPoint blk
p, BlockNo
bno) <- [(SlotNo, RealPoint blk, BlockNo)]
nodeEventsSelects
]
, nodeOutputInvalids :: Map (RealPoint blk) [ExtValidationError blk]
nodeOutputInvalids = (ExtValidationError blk
-> [ExtValidationError blk] -> [ExtValidationError blk]
forall a. a -> [a] -> [a]
:[]) (ExtValidationError blk -> [ExtValidationError blk])
-> Map (RealPoint blk) (ExtValidationError blk)
-> Map (RealPoint blk) [ExtValidationError blk]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(RealPoint blk, ExtValidationError blk)]
-> Map (RealPoint blk) (ExtValidationError blk)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(RealPoint blk, ExtValidationError blk)]
nodeEventsInvalids
, nodeOutputNodeDBs :: NodeDBs MockFS
nodeOutputNodeDBs = NodeDBs MockFS
nodeInfoDBs
, nodeOutputUpdates :: [LedgerUpdate blk]
nodeOutputUpdates = [LedgerUpdate blk]
nodeEventsUpdates
, nodePipeliningEvents :: [TracePipeliningEvent blk]
nodePipeliningEvents = [TracePipeliningEvent blk]
nodeEventsPipelining
}
pure
( Map.singleton nid nodeOutput
, Map.singleton nid <$> Map.fromList nodeEventsTipBlockNos
)
pure $ TestOutput
{ testOutputNodes = Map.unions nodeOutputs'
, testOutputTipBlockNos = Map.unionsWith Map.union tipBlockNos'
}
nullDebugTracer :: (Applicative m, Show a) => Tracer m a
nullDebugTracer :: forall (m :: * -> *) a. (Applicative m, Show a) => Tracer m a
nullDebugTracer = Tracer m a
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer Tracer m a -> Tracer m a -> Tracer m a
forall a. a -> a -> a
`asTypeOf` Tracer m String -> Tracer m a
forall a (m :: * -> *). Show a => Tracer m String -> Tracer m a
showTracing Tracer m String
forall (m :: * -> *). Applicative m => Tracer m String
debugTracer
nullDebugTracers ::
( Monad m
, Show peer
, LedgerSupportsProtocol blk
, TracingConstraints blk
)
=> Tracers m peer Void blk
nullDebugTracers :: forall (m :: * -> *) peer blk.
(Monad m, Show peer, LedgerSupportsProtocol blk,
TracingConstraints blk) =>
Tracers m peer Void blk
nullDebugTracers = Tracers m peer Void blk
forall (m :: * -> *) remotePeer localPeer blk.
Monad m =>
Tracers m remotePeer localPeer blk
nullTracers Tracers m peer Void blk
-> Tracers m peer Void blk -> Tracers m peer Void blk
forall a. a -> a -> a
`asTypeOf` Tracer m String -> Tracers m peer Void blk
forall blk remotePeer (m :: * -> *) localPeer.
(Show blk, Show (GenTx blk), Show (Validated (GenTx blk)),
Show (GenTxId blk), Show (ApplyTxErr blk), Show (Header blk),
Show (ForgeStateInfo blk), Show (ForgeStateUpdateError blk),
Show (CannotForge blk), Show remotePeer,
LedgerSupportsProtocol blk) =>
Tracer m String -> Tracers m remotePeer localPeer blk
showTracers Tracer m String
forall (m :: * -> *). Applicative m => Tracer m String
debugTracer
nullDebugProtocolTracers ::
( Monad m
, HasHeader blk
, TracingConstraints blk
, Show peer
)
=> NTN.Tracers m peer blk failure
nullDebugProtocolTracers :: forall (m :: * -> *) blk peer failure.
(Monad m, HasHeader blk, TracingConstraints blk, Show peer) =>
Tracers m peer blk failure
nullDebugProtocolTracers =
Tracers m peer blk failure
forall (m :: * -> *) ntnAddr blk e.
Monad m =>
Tracers m ntnAddr blk e
NTN.nullTracers Tracers m peer blk failure
-> Tracers m peer blk failure -> Tracers m peer blk failure
forall a. a -> a -> a
`asTypeOf` Tracer m String -> Tracers m peer blk failure
forall blk ntnAddr (m :: * -> *) e.
(Show blk, Show ntnAddr, Show (Header blk), Show (GenTx blk),
Show (GenTxId blk), HasHeader blk, HasNestedContent Header blk) =>
Tracer m String -> Tracers m ntnAddr blk e
NTN.showTracers Tracer m String
forall (m :: * -> *). Applicative m => Tracer m String
debugTracer
type TracingConstraints blk =
( Show blk
, Show (ApplyTxErr blk)
, Show (Header blk)
, Show (GenTx blk)
, Show (Validated (GenTx blk))
, Show (GenTxId blk)
, Show (ForgeStateInfo blk)
, Show (ForgeStateUpdateError blk)
, Show (CannotForge blk)
, HasNestedContent Header blk
)
withAsyncsWaitAny :: forall m a. IOLike m => NE.NonEmpty (m a) -> m a
withAsyncsWaitAny :: forall (m :: * -> *) a. IOLike m => NonEmpty (m a) -> m a
withAsyncsWaitAny = [Async m a] -> [m a] -> m a
forall {f :: * -> *} {b}.
MonadAsync f =>
[Async f b] -> [f b] -> f b
go [] ([m a] -> m a)
-> (NonEmpty (m a) -> [m a]) -> NonEmpty (m a) -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (m a) -> [m a]
forall a. NonEmpty a -> [a]
NE.toList
where
go :: [Async f b] -> [f b] -> f b
go [Async f b]
acc = \case
[] -> (Async f b, b) -> b
forall a b. (a, b) -> b
snd ((Async f b, b) -> b) -> f (Async f b, b) -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Async f b] -> f (Async f b, b)
forall a. [Async f a] -> f (Async f a, a)
forall (m :: * -> *) a.
MonadAsync m =>
[Async m a] -> m (Async m a, a)
waitAny [Async f b]
acc
f b
m:[f b]
ms -> f b -> (Async f b -> f b) -> f b
forall a b. f a -> (Async f a -> f b) -> f b
forall (m :: * -> *) a b.
MonadAsync m =>
m a -> (Async m a -> m b) -> m b
withAsync f b
m ((Async f b -> f b) -> f b) -> (Async f b -> f b) -> f b
forall a b. (a -> b) -> a -> b
$ \Async f b
h -> [Async f b] -> [f b] -> f b
go (Async f b
hAsync f b -> [Async f b] -> [Async f b]
forall a. a -> [a] -> [a]
:[Async f b]
acc) [f b]
ms
data LimitedApp m addr blk =
LimitedApp (LimitedApp' m addr blk)
type LimitedApp' m addr blk =
NTN.Apps m addr
Lazy.ByteString
Lazy.ByteString
(AnyMessage (TxSubmission2 (GenTxId blk) (GenTx blk)))
(AnyMessage KeepAlive)
(AnyMessage (PeerSharing addr))
NodeToNodeInitiatorResult ()
data MiniProtocolState = MiniProtocolDelayed | MiniProtocolRestarting
deriving (Int -> MiniProtocolState -> ShowS
[MiniProtocolState] -> ShowS
MiniProtocolState -> String
(Int -> MiniProtocolState -> ShowS)
-> (MiniProtocolState -> String)
-> ([MiniProtocolState] -> ShowS)
-> Show MiniProtocolState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MiniProtocolState -> ShowS
showsPrec :: Int -> MiniProtocolState -> ShowS
$cshow :: MiniProtocolState -> String
show :: MiniProtocolState -> String
$cshowList :: [MiniProtocolState] -> ShowS
showList :: [MiniProtocolState] -> ShowS
Show)
data MiniProtocolFatalException = MiniProtocolFatalException
{ MiniProtocolFatalException -> TypeRep
mpfeType :: !Typeable.TypeRep
, MiniProtocolFatalException -> SomeException
mpfeExn :: !SomeException
, MiniProtocolFatalException -> CoreNodeId
mpfeClient :: !CoreNodeId
, MiniProtocolFatalException -> CoreNodeId
mpfeServer :: !CoreNodeId
}
deriving (Int -> MiniProtocolFatalException -> ShowS
[MiniProtocolFatalException] -> ShowS
MiniProtocolFatalException -> String
(Int -> MiniProtocolFatalException -> ShowS)
-> (MiniProtocolFatalException -> String)
-> ([MiniProtocolFatalException] -> ShowS)
-> Show MiniProtocolFatalException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MiniProtocolFatalException -> ShowS
showsPrec :: Int -> MiniProtocolFatalException -> ShowS
$cshow :: MiniProtocolFatalException -> String
show :: MiniProtocolFatalException -> String
$cshowList :: [MiniProtocolFatalException] -> ShowS
showList :: [MiniProtocolFatalException] -> ShowS
Show)
instance Exception MiniProtocolFatalException
data JitEbbError blk
= JitEbbError (LedgerError blk)
deriving instance LedgerSupportsProtocol blk => Show (JitEbbError blk)
instance LedgerSupportsProtocol blk => Exception (JitEbbError blk)
data TxGenFailure = TxGenFailure Int
deriving (Int -> TxGenFailure -> ShowS
[TxGenFailure] -> ShowS
TxGenFailure -> String
(Int -> TxGenFailure -> ShowS)
-> (TxGenFailure -> String)
-> ([TxGenFailure] -> ShowS)
-> Show TxGenFailure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxGenFailure -> ShowS
showsPrec :: Int -> TxGenFailure -> ShowS
$cshow :: TxGenFailure -> String
show :: TxGenFailure -> String
$cshowList :: [TxGenFailure] -> ShowS
showList :: [TxGenFailure] -> ShowS
Show)
instance Exception TxGenFailure
neUnzip :: Functor f => f (a,b) -> (f a, f b)
neUnzip :: forall (f :: * -> *) a b. Functor f => f (a, b) -> (f a, f b)
neUnzip f (a, b)
xs = ((a, b) -> a
forall a b. (a, b) -> a
fst ((a, b) -> a) -> f (a, b) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (a, b)
xs, (a, b) -> b
forall a b. (a, b) -> b
snd ((a, b) -> b) -> f (a, b) -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (a, b)
xs)