Skip to content

Commit

Permalink
GSM: use diffusion layer info for HAA
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen committed Apr 29, 2024
1 parent f25ea0b commit c133df7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Non-Breaking

- Implemented the Honest Availability Assumption properly (both for
Praos/"Genesis Lite" and Genesis) based on newly exposed state by the
diffusion layer.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import qualified Codec.CBOR.Encoding as CBOR
import Codec.Serialise (DeserialiseFailure)
import qualified Control.Concurrent.Class.MonadSTM.Strict as StrictSTM
import Control.DeepSeq (NFData)
import Control.Monad (when)
import Control.Monad.Class.MonadTime.SI (MonadTime)
import Control.Monad.Class.MonadTimer.SI (MonadTimer)
import Control.Tracer (Tracer, contramap, traceWith)
Expand Down Expand Up @@ -626,7 +627,11 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
lpGetLatestSlot = getImmTipSlot kernel,
lpGetLedgerPeers = fromMaybe [] <$> getPeersFromCurrentLedger kernel (const True),
lpGetLedgerStateJudgement = getLedgerStateJudgement kernel
}
},
Diffusion.daUpdateOutboundConnectionsState =
let varOcs = getOutboundConnectionsState kernel in \newOcs -> do
oldOcs <- readTVar varOcs
when (newOcs /= oldOcs) $ writeTVar varOcs newOcs
}

localRethrowPolicy :: RethrowPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ import Ouroboros.Network.NodeToNode (ConnectionId,
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers)
import Ouroboros.Network.PeerSelection.LedgerPeers.Type
(LedgerStateJudgement (..))
import Ouroboros.Network.PeerSelection.LocalRootPeers
(OutboundConnectionsState (..))
import Ouroboros.Network.PeerSharing (PeerSharingAPI,
PeerSharingRegistry, newPeerSharingAPI,
newPeerSharingRegistry, ps_POLICY_PEER_SHARE_MAX_PEERS,
Expand Down Expand Up @@ -149,6 +151,11 @@ data NodeKernel m addrNTN addrNTC blk = NodeKernel {
, setBlockForging :: [BlockForging m blk] -> m ()

, getPeerSharingAPI :: PeerSharingAPI addrNTN StdGen m

-- | Whether we are or will ever be connected to remote/external
-- (bootstrap) peers.
, getOutboundConnectionsState
:: StrictTVar m OutboundConnectionsState
}

-- | Arguments required when initializing a node
Expand Down Expand Up @@ -204,6 +211,8 @@ initNodeKernel args@NodeKernelArgs { registry, cfg, tracers
, varLedgerJudgement
} = st

varPeerConnectivity <- newTVarIO UntrustedState

do let GsmNodeKernelArgs {..} = gsmArgs
gsmTracerArgs =
( castTip . either AF.anchorToTip tipFromHeader . AF.head . fst
Expand Down Expand Up @@ -239,9 +248,12 @@ initNodeKernel args@NodeKernelArgs { registry, cfg, tracers
gsmMarkerFileView
, GSM.writeGsmState = \x -> atomically $ do
writeTVar varLedgerJudgement $ GSM.gsmStateToLedgerJudgement x
, -- In the context of bootstrap peers, it is fine to always
-- return 'True' as all peers are trusted during syncing.
GSM.isHaaSatisfied = pure True
, GSM.isHaaSatisfied = do
readTVar varPeerConnectivity <&> \case
-- See the upstream Haddocks for when the diffusion layer is
-- in this state.
TrustedStateWithExternalPeers -> True
UntrustedState -> False
}
judgment <- readTVarIO varLedgerJudgement
void $ forkLinkedThread registry "NodeKernel.GSM" $ case judgment of
Expand Down Expand Up @@ -278,6 +290,8 @@ initNodeKernel args@NodeKernelArgs { registry, cfg, tracers
, getTracers = tracers
, setBlockForging = \a -> atomically . LazySTM.putTMVar blockForgingVar $! a
, getPeerSharingAPI = peerSharingAPI
, getOutboundConnectionsState
= varPeerConnectivity
}
where
blockForgingController :: InternalState m remotePeer localPeer blk
Expand Down

0 comments on commit c133df7

Please sign in to comment.