Skip to content

Commit

Permalink
Don't use stale targets lingering since last churning
Browse files Browse the repository at this point in the history
In Genesis sync mode, when we aren't actively churning,
the targets basis in the TVar can become stale when
ledger state judgement flips. We don't want to use these
targets when that happens and so we add a check for this condition,
and instead set the targets in the private OG state based on
the targets appropriate for the current ledger state judgement.
When churn wakes up for the next round, it will use the appropriate
targets basis and then we can use the targets that churn modifies
and provides us with.
  • Loading branch information
crocodile-dentist committed Jul 16, 2024
1 parent 9ce1fd7 commit 9e192f6
Showing 1 changed file with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,39 @@ targetPeers :: (MonadSTM m, Ord peeraddr)
=> PeerSelectionActions peeraddr peerconn m
-> PeerSelectionState peeraddr peerconn
-> Guarded (STM m) (TimedDecision m peeraddr peerconn)
targetPeers PeerSelectionActions{ readPeerSelectionTargets }
targetPeers PeerSelectionActions{ readPeerSelectionTargets,
peerTargets = ConsensusModePeerTargets {
deadlineTargets,
syncTargets } }
st@PeerSelectionState{
publicRootPeers,
localRootPeers,
targets,
bootstrapPeersFlag,
hasOnlyBootstrapPeers,
ledgerStateJudgement
ledgerStateJudgement,
consensusMode
} =
Guarded Nothing $ do
targets' <- readPeerSelectionTargets
churnTargets <- readPeerSelectionTargets
-- Genesis consensus mode:
-- we check if targets proposed by churn are stale
-- in the sense that they are the targets for
-- opposite value of the current ledger state judgement.
-- This indicates that we aren't churning currently, and
-- furthermore it means that the ledger state has flipped since
-- we last churned. Therefore we can't set the targets from
-- the TVar, and instead we set the appropriate targets
-- for the mode we are in.
let targets' =
case (ledgerStateJudgement, consensusMode) of
(YoungEnough, GenesisMode)
| churnTargets == syncTargets ->
deadlineTargets
(TooOld, GenesisMode)
| churnTargets == deadlineTargets ->
syncTargets
_otherwise -> churnTargets

-- nb. first check is redundant in Genesis mode
check ( isNodeAbleToMakeProgress bootstrapPeersFlag
Expand Down Expand Up @@ -578,10 +600,7 @@ monitorLedgerStateJudgement :: ( MonadSTM m
=> PeerSelectionActions peeraddr peerconn m
-> PeerSelectionState peeraddr peerconn
-> Guarded (STM m) (TimedDecision m peeraddr peerconn)
monitorLedgerStateJudgement PeerSelectionActions{ readLedgerStateJudgement,
peerTargets = ConsensusModePeerTargets{
praosTargets,
genesisSyncTargets } }
monitorLedgerStateJudgement PeerSelectionActions{ readLedgerStateJudgement }
st@PeerSelectionState{ bootstrapPeersFlag,
publicRootPeers,
knownPeers,
Expand All @@ -594,17 +613,13 @@ monitorLedgerStateJudgement PeerSelectionActions{ readLedgerStateJudgement,
Guarded Nothing $ do
lsj <- readLedgerStateJudgement
check (lsj /= ledgerStateJudgement)
let targets = case lsj of
YoungEnough -> praosTargets
TooOld -> genesisSyncTargets

return $ \_now ->
Decision {
decisionTrace = [TraceLedgerStateJudgementChanged lsj],
decisionJobs = [],
decisionState = st {
ledgerStateJudgement = lsj,
targets } }
ledgerStateJudgement = lsj } }

| PraosMode <- consensusMode
, isBootstrapPeersEnabled bootstrapPeersFlag =
Expand Down

0 comments on commit 9e192f6

Please sign in to comment.