Skip to content

Commit

Permalink
Remove WhetherReceivingTentativeBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
crocodile-dentist committed Oct 8, 2024
1 parent c6fff3a commit 099b654
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module Ouroboros.Network.BlockFetch.ConsensusInterface
( FetchMode (..)
, BlockFetchConsensusInterface (..)
, WhetherReceivingTentativeBlocks (..)
, FromConsensus (..)
) where

Expand Down Expand Up @@ -86,8 +85,7 @@ data BlockFetchConsensusInterface peer header block m =
-- That function and 'readFetchedBlocks' are required to be linked. Upon
-- successful completion of @addFetchedBlock@ it must be the case that
-- 'readFetchedBlocks' reports the block.
mkAddFetchedBlock :: WhetherReceivingTentativeBlocks
-> STM m (Point block -> block -> m ()),
mkAddFetchedBlock :: STM m (Point block -> block -> m ()),

-- | The highest stored/downloaded slot number.
--
Expand Down Expand Up @@ -152,13 +150,6 @@ data BlockFetchConsensusInterface peer header block m =
blockForgeUTCTime :: FromConsensus block -> STM m UTCTime
}


-- | Whether the block fetch peer is sending tentative blocks, which are
-- understood to possibly be invalid
data WhetherReceivingTentativeBlocks
= ReceivingTentativeBlocks
| NotReceivingTentativeBlocks

{-------------------------------------------------------------------------------
Syntactic indicator of key precondition about Consensus time conversions
-------------------------------------------------------------------------------}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Ouroboros.Network.NodeToNode.Version
, ConnectionMode (..)
, nodeToNodeVersionCodec
, nodeToNodeCodecCBORTerm
, isPipeliningEnabled
) where

import Data.Text (Text)
Expand All @@ -20,8 +19,6 @@ import Codec.CBOR.Term qualified as CBOR

import Control.DeepSeq
import GHC.Generics
import Ouroboros.Network.BlockFetch.ConsensusInterface
(WhetherReceivingTentativeBlocks (..))
import Ouroboros.Network.CodecCBORTerm
import Ouroboros.Network.Handshake.Acceptable (Accept (..), Acceptable (..))
import Ouroboros.Network.Handshake.Queryable (Queryable (..))
Expand Down
3 changes: 1 addition & 2 deletions ouroboros-network/demo/chain-sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import Ouroboros.Network.Mock.ConcreteBlock
import Ouroboros.Network.Mux
import Ouroboros.Network.NodeToClient (LocalConnectionId)
import Ouroboros.Network.NodeToNode
import Ouroboros.Network.NodeToNode.Version (isPipeliningEnabled)
import Ouroboros.Network.Point (WithOrigin (..))
import Ouroboros.Network.Snocket
import Ouroboros.Network.Socket
Expand Down Expand Up @@ -399,7 +398,7 @@ clientBlockFetch sockAddrs maxSlotNo = withIOManager $ \iocp -> do
InitiatorProtocolOnly $
MiniProtocolCb $ \MinimalInitiatorContext { micConnectionId = connId } channel ->
bracketDqRegistry registry connId $
bracketFetchClient registry maxBound isPipeliningEnabled connId $ \clientCtx -> do
bracketFetchClient registry maxBound connId $ \clientCtx -> do
threadDelay 1000000
runPipelinedPeer
nullTracer -- (contramap (show . TraceLabelPeer ("block-fetch", getFilePath $ remoteAddress connId)) stdoutTracer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ blockFetchExample0 decisionTracer clientStateTracer clientMsgTracer
(contramap (TraceLabelPeer peerno) clientMsgTracer)
(contramap (TraceLabelPeer peerno) serverMsgTracer)
(maxBound :: NodeToNodeVersion)
NodeToNode.isPipeliningEnabled
clientDelay serverDelay
registry peerno
(blockFetchClient NodeToNodeV_13 controlMessageSTM nullTracer)
Expand Down Expand Up @@ -325,15 +324,14 @@ runFetchClient :: (MonadAsync m, MonadFork m, MonadMask m, MonadThrow (STM m),
block, Serialise point, ShowProxy block)
=> Tracer m (TraceSendRecv (BlockFetch block point))
-> version
-> (version -> WhetherReceivingTentativeBlocks)
-> FetchClientRegistry peerid header block m
-> peerid
-> Channel m LBS.ByteString
-> ( FetchClientContext header block m
-> ClientPipelined (BlockFetch block point) BFIdle m a)
-> m a
runFetchClient tracer version isPipeliningEnabled registry peerid channel client =
bracketFetchClient registry version isPipeliningEnabled peerid $ \clientCtx ->
runFetchClient tracer version registry peerid channel client =
bracketFetchClient registry version peerid $ \clientCtx ->
fst <$>
runPipelinedPeerWithLimits tracer codec (byteLimitsBlockFetch (fromIntegral . LBS.length))
timeLimitsBlockFetch channel (client clientCtx)
Expand Down Expand Up @@ -365,8 +363,6 @@ runFetchClientAndServerAsync
=> Tracer m (TraceSendRecv (BlockFetch block (Point block)))
-> Tracer m (TraceSendRecv (BlockFetch block (Point block)))
-> version
-> (version -> WhetherReceivingTentativeBlocks)
-- ^ is pipelining enabled function
-> Maybe DiffTime -- ^ client's channel delay
-> Maybe DiffTime -- ^ server's channel delay
-> FetchClientRegistry peerid header block m
Expand All @@ -376,7 +372,7 @@ runFetchClientAndServerAsync
-> BlockFetchServer block (Point block) m b
-> m (Async m a, Async m b, Async m (), Async m ())
runFetchClientAndServerAsync clientTracer serverTracer
version isPipeliningEnabled
version
clientDelay serverDelay
registry peerid client server = do
(clientChannel, serverChannel) <- createConnectedChannels
Expand All @@ -387,7 +383,6 @@ runFetchClientAndServerAsync clientTracer serverTracer
runFetchClient
clientTracer
version
isPipeliningEnabled
registry peerid
(fromMaybe id (delayChannel <$> clientDelay) clientChannel)
client
Expand Down
10 changes: 4 additions & 6 deletions ouroboros-network/src/Ouroboros/Network/BlockFetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ module Ouroboros.Network.BlockFetch
, FetchMode (..)
, FromConsensus (..)
, SizeInBytes
, WhetherReceivingTentativeBlocks (..)
) where

import Data.Hashable (Hashable)
Expand All @@ -118,8 +117,7 @@ import Ouroboros.Network.BlockFetch.ClientRegistry (FetchClientPolicy (..),
readFetchClientsStateVars, readFetchClientsStatus, readPeerGSVs,
setFetchClientContext)
import Ouroboros.Network.BlockFetch.ConsensusInterface
(BlockFetchConsensusInterface (..), FromConsensus (..),
WhetherReceivingTentativeBlocks (..))
(BlockFetchConsensusInterface (..), FromConsensus (..))
import Ouroboros.Network.BlockFetch.State


Expand Down Expand Up @@ -180,9 +178,9 @@ blockFetchLogic decisionTracer clientStateTracer
fetchTriggerVariables
fetchNonTriggerVariables
where
mkFetchClientPolicy :: WhetherReceivingTentativeBlocks -> STM m (FetchClientPolicy header block m)
mkFetchClientPolicy receivingTentativeBlocks = do
addFetchedBlock <- mkAddFetchedBlock receivingTentativeBlocks
mkFetchClientPolicy :: STM m (FetchClientPolicy header block m)
mkFetchClientPolicy = do
addFetchedBlock <- mkAddFetchedBlock
pure FetchClientPolicy {
blockFetchSize,
blockMatchesHeader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ data FetchClientRegistry peer header block m =
fcrCtxVar
:: StrictTMVar
m ( Tracer m (TraceLabelPeer peer (TraceFetchClientState header))
, WhetherReceivingTentativeBlocks
-> STM m (FetchClientPolicy header block m)
, STM m (FetchClientPolicy header block m)
),
fcrFetchRegistry
:: StrictTVar m (Map peer (FetchClientStateVars m header)),
Expand Down Expand Up @@ -85,14 +84,12 @@ bracketFetchClient :: forall m a peer header block version.
(MonadFork m, MonadMask m, MonadTimer m, Ord peer)
=> FetchClientRegistry peer header block m
-> version
-> (version -> WhetherReceivingTentativeBlocks)
-- ^ is pipelining enabled function
-> peer
-> (FetchClientContext header block m -> m a)
-> m a
bracketFetchClient (FetchClientRegistry ctxVar
fetchRegistry syncRegistry dqRegistry keepRegistry dyingRegistry)
version isPipeliningEnabled peer action = do
_version peer action = do
ksVar <- newEmptyTMVarIO
bracket (register ksVar) (uncurry (unregister ksVar)) (action . fst)
where
Expand Down Expand Up @@ -121,9 +118,7 @@ bracketFetchClient (FetchClientRegistry ctxVar
Map.insert peer (tid, ksVar) m

-- allocate the policy specific for this peer's negotiated version
policy <- do
let pipeliningEnabled = isPipeliningEnabled version
mkPolicy pipeliningEnabled
policy <- mkPolicy

stateVars <- newFetchClientStateVars
modifyTVar fetchRegistry $ \m ->
Expand Down Expand Up @@ -322,9 +317,7 @@ bracketKeepAliveClient(FetchClientRegistry _ctxVar
setFetchClientContext :: MonadSTM m
=> FetchClientRegistry peer header block m
-> Tracer m (TraceLabelPeer peer (TraceFetchClientState header))
-> ( WhetherReceivingTentativeBlocks
-> STM m (FetchClientPolicy header block m)
)
-> STM m (FetchClientPolicy header block m)
-> m ()
setFetchClientContext (FetchClientRegistry ctxVar _ _ _ _ _) tracer mkPolicy =
atomically $ do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Ouroboros.Network.BlockFetch.ClientState
, ChainRange (..)
-- * Ancillary
, FromConsensus (..)
, WhetherReceivingTentativeBlocks (..)
) where

import Data.List as List (foldl')
Expand All @@ -52,8 +51,7 @@ import Network.Mux.Trace (TraceLabelPeer (..))
import Ouroboros.Network.AnchoredFragment (AnchoredFragment)
import Ouroboros.Network.AnchoredFragment qualified as AF
import Ouroboros.Network.Block (HasHeader, MaxSlotNo (..), Point, blockPoint)
import Ouroboros.Network.BlockFetch.ConsensusInterface (FromConsensus (..),
WhetherReceivingTentativeBlocks (..))
import Ouroboros.Network.BlockFetch.ConsensusInterface (FromConsensus (..))
import Ouroboros.Network.BlockFetch.DeltaQ (PeerFetchInFlightLimits (..),
PeerGSV, SizeInBytes, calculatePeerFetchInFlightLimits)
import Ouroboros.Network.ControlMessage (ControlMessageSTM,
Expand Down

0 comments on commit 099b654

Please sign in to comment.