@@ -33,7 +33,7 @@ import Ouroboros.Consensus.Ledger.SupportsProtocol
33
33
)
34
34
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client as CSClient
35
35
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client.Jumping as CSJumping
36
- import Ouroboros.Consensus.Peras.Weight (emptyPerasWeightSnapshot )
36
+ import Ouroboros.Consensus.Peras.Weight (PerasWeightSnapshot )
37
37
import Ouroboros.Consensus.Storage.ChainDB.API
38
38
( AddBlockPromise
39
39
, ChainDB
@@ -46,11 +46,13 @@ import qualified Ouroboros.Consensus.Storage.ChainDB.API.Types.InvalidBlockPunis
46
46
import Ouroboros.Consensus.Util.AnchoredFragment
47
47
import Ouroboros.Consensus.Util.IOLike
48
48
import Ouroboros.Consensus.Util.Orphans ()
49
+ import Ouroboros.Consensus.Util.STM
49
50
import Ouroboros.Network.AnchoredFragment (AnchoredFragment )
50
51
import qualified Ouroboros.Network.AnchoredFragment as AF
51
52
import Ouroboros.Network.Block (MaxSlotNo )
52
53
import Ouroboros.Network.BlockFetch.ConsensusInterface
53
54
( BlockFetchConsensusInterface (.. )
55
+ , ChainComparison (.. )
54
56
, ChainSelStarvation
55
57
, FetchMode (.. )
56
58
, FromConsensus (.. )
@@ -67,6 +69,7 @@ data ChainDbView m blk = ChainDbView
67
69
, getMaxSlotNo :: STM m MaxSlotNo
68
70
, addBlockAsync :: InvalidBlockPunishment m -> blk -> m (AddBlockPromise m blk )
69
71
, getChainSelStarvation :: STM m ChainSelStarvation
72
+ , getPerasWeightSnapshot :: STM m (WithFingerprint (PerasWeightSnapshot blk ))
70
73
}
71
74
72
75
defaultChainDbView :: ChainDB m blk -> ChainDbView m blk
@@ -78,6 +81,7 @@ defaultChainDbView chainDB =
78
81
, getMaxSlotNo = ChainDB. getMaxSlotNo chainDB
79
82
, addBlockAsync = ChainDB. addBlockAsync chainDB
80
83
, getChainSelStarvation = ChainDB. getChainSelStarvation chainDB
84
+ , getPerasWeightSnapshot = ChainDB. getPerasWeightSnapshot chainDB
81
85
}
82
86
83
87
readFetchModeDefault ::
@@ -227,6 +231,16 @@ mkBlockFetchConsensusInterface
227
231
readFetchedMaxSlotNo :: STM m MaxSlotNo
228
232
readFetchedMaxSlotNo = getMaxSlotNo chainDB
229
233
234
+ readChainComparison :: STM m (WithFingerprint (ChainComparison (HeaderWithTime blk )))
235
+ readChainComparison =
236
+ fmap mkChainComparison <$> getPerasWeightSnapshot chainDB
237
+ where
238
+ mkChainComparison weights =
239
+ ChainComparison
240
+ { plausibleCandidateChain = plausibleCandidateChain weights
241
+ , compareCandidateChains = compareCandidateChains weights
242
+ }
243
+
230
244
-- Note that @ours@ comes from the ChainDB and @cand@ from the ChainSync
231
245
-- client.
232
246
--
@@ -242,10 +256,11 @@ mkBlockFetchConsensusInterface
242
256
-- fragment, our current chain might have changed.
243
257
plausibleCandidateChain ::
244
258
HasCallStack =>
259
+ PerasWeightSnapshot blk ->
245
260
AnchoredFragment (HeaderWithTime blk ) ->
246
261
AnchoredFragment (HeaderWithTime blk ) ->
247
262
Bool
248
- plausibleCandidateChain ours cand =
263
+ plausibleCandidateChain weights ours cand =
249
264
-- 1. The ChainDB maintains the invariant that the anchor of our fragment
250
265
-- corresponds to the immutable tip.
251
266
--
@@ -270,13 +285,11 @@ mkBlockFetchConsensusInterface
270
285
Just _ -> preferAnchoredCandidate bcfg weights ours cand
271
286
272
287
compareCandidateChains ::
288
+ PerasWeightSnapshot blk ->
273
289
AnchoredFragment (HeaderWithTime blk ) ->
274
290
AnchoredFragment (HeaderWithTime blk ) ->
275
291
Ordering
276
- compareCandidateChains = compareAnchoredFragments bcfg weights
277
-
278
- -- TODO requires https://github.com/IntersectMBO/ouroboros-network/pull/5161
279
- weights = emptyPerasWeightSnapshot
292
+ compareCandidateChains = compareAnchoredFragments bcfg
280
293
281
294
headerForgeUTCTime :: FromConsensus (HeaderWithTime blk ) -> STM m UTCTime
282
295
headerForgeUTCTime =
0 commit comments