Skip to content

Commit c06b883

Browse files
authored
ChainSync client: remove redundant intersection check (#1080)
This step has caused confusions in the past. See the commit description of the single commit.
2 parents 7565499 + bf8a039 commit c06b883

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Non-Breaking
2+
3+
- ChainSync client: removed redundant intersection check with selection (we
4+
already do that on every RollForward).

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ChainSync/Client.hs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,6 @@ knownIntersectionStateTop cfgEnv dynEnv intEnv =
10991099
InternalEnv {
11001100
drainThePipe
11011101
, headerInFutureCheck
1102-
, intersectsWithCurrentChain
11031102
, terminateAfterDrain
11041103
, traceException
11051104
} = intEnv
@@ -1108,13 +1107,7 @@ knownIntersectionStateTop cfgEnv dynEnv intEnv =
11081107
recordHeaderArrival
11091108
} = headerInFutureCheck
11101109

1111-
-- Request the next message (roll forward or backward), unless our chain
1112-
-- has changed such that it no longer intersects with the candidate, in
1113-
-- which case we initiate the intersection finding part of the protocol.
1114-
--
1115-
-- This is the main place we check whether our current chain has changed.
1116-
-- We also check it in 'rollForward' to make sure we have an up-to-date
1117-
-- intersection before calling 'getLedgerView'.
1110+
-- Request the next message (roll forward or backward).
11181111
--
11191112
-- This is also the place where we checked whether we're asked to terminate
11201113
-- by the mux layer.
@@ -1129,36 +1122,14 @@ knownIntersectionStateTop cfgEnv dynEnv intEnv =
11291122
atomically controlMessageSTM >>= \case
11301123
-- We have been asked to terminate the client
11311124
Terminate -> terminateAfterDrain n $ AskedToTerminate
1132-
_continue -> do
1133-
atomically (intersectsWithCurrentChain kis) >>= \case
1134-
-- Our chain (tip) didn't change or if it did, it still
1135-
-- intersects with the candidate fragment, so we can
1136-
-- continue requesting the next block.
1137-
StillIntersects () kis' -> do
1138-
let KnownIntersectionState {
1139-
theirFrag
1140-
} = kis'
1141-
atomically $ do
1142-
setCandidate theirFrag
1143-
return $
1144-
requestNext
1145-
kis'
1146-
mkPipelineDecision
1147-
n
1148-
theirTip
1149-
(AF.headBlockNo theirFrag)
1150-
-- Our chain (tip) has changed and it no longer intersects
1151-
-- with the candidate fragment, so we have to find a new
1152-
-- intersection, but first drain the pipe.
1153-
NoLongerIntersects ->
1154-
continueWithState ()
1155-
$ drainThePipe n
1156-
$ findIntersectionTop
1157-
cfgEnv
1158-
dynEnv
1159-
intEnv
1160-
(kBestBlockNo kis)
1161-
NoMoreIntersection
1125+
_continue ->
1126+
return $
1127+
requestNext
1128+
kis
1129+
mkPipelineDecision
1130+
n
1131+
theirTip
1132+
(AF.headBlockNo (theirFrag kis))
11621133

11631134
requestNext ::
11641135
KnownIntersectionState blk
@@ -1247,6 +1218,13 @@ knownIntersectionStateTop cfgEnv dynEnv intEnv =
12471218
(Their theirTip)
12481219
}
12491220

1221+
-- Process a new header.
1222+
--
1223+
-- This is also the place where we check whether their chain still
1224+
-- intersects with ours. We have to do this in order to get a ledger state
1225+
-- to forecast from. It is also sufficient to do this just here, and not on
1226+
-- MsgRollBack or MsgAwaitReply as these do not induce significant work in
1227+
-- the context of ChainSync.
12501228
rollForward ::
12511229
MkPipelineDecision
12521230
-> Nat n

0 commit comments

Comments
 (0)