File tree Expand file tree Collapse file tree 2 files changed +9
-23
lines changed
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus Expand file tree Collapse file tree 2 files changed +9
-23
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ module Ouroboros.Consensus.Peras.Weight
12
12
, mkPerasWeightSnapshot
13
13
, perasWeightSnapshotToList
14
14
, addToPerasWeightSnapshot
15
- , removeFromPerasWeightSnapshot
15
+ , prunePerasWeightSnapshot
16
16
, weightBoostOfPoint
17
17
, weightBoostOfFragment
18
18
) where
@@ -57,19 +57,15 @@ addToPerasWeightSnapshot ::
57
57
addToPerasWeightSnapshot pt weight =
58
58
PerasWeightSnapshot . Map. insertWith (<>) pt weight . getPerasWeightSnapshot
59
59
60
- removeFromPerasWeightSnapshot ::
61
- StandardHash blk =>
62
- Point blk ->
63
- PerasWeight ->
60
+ prunePerasWeightSnapshot ::
61
+ SlotNo ->
64
62
PerasWeightSnapshot blk ->
65
63
PerasWeightSnapshot blk
66
- removeFromPerasWeightSnapshot pt ( PerasWeight weight) =
67
- PerasWeightSnapshot . Map. update subtractWeight pt . getPerasWeightSnapshot
64
+ prunePerasWeightSnapshot slot =
65
+ PerasWeightSnapshot . Map. dropWhileAntitone isTooOld . getPerasWeightSnapshot
68
66
where
69
- subtractWeight :: PerasWeight -> Maybe PerasWeight
70
- subtractWeight (PerasWeight w)
71
- | w > weight = Just $ PerasWeight (w - weight)
72
- | otherwise = Nothing
67
+ isTooOld :: Point blk -> Bool
68
+ isTooOld pt = pointSlot pt < NotOrigin slot
73
69
74
70
weightBoostOfPoint ::
75
71
forall blk .
Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ module Ouroboros.Consensus.Storage.PerasCertDB.Impl
21
21
) where
22
22
23
23
import Control.Tracer (Tracer , nullTracer , traceWith )
24
- import Data.Foldable as Foldable (foldl' )
25
24
import Data.Kind (Type )
26
25
import Data.Map.Strict (Map )
27
26
import qualified Data.Map.Strict as Map
@@ -201,19 +200,10 @@ implGarbageCollect PerasCertDbEnv{pcdbVolatileState} slot =
201
200
gc PerasVolatileCertState {pvcsCerts, pvcsWeightByPoint} =
202
201
PerasVolatileCertState
203
202
{ pvcsCerts = certsToKeep
204
- , pvcsWeightByPoint =
205
- Foldable. foldl'
206
- ( \ s cert ->
207
- removeFromPerasWeightSnapshot
208
- (perasCertBoostedBlock cert)
209
- boostPerCert
210
- s
211
- )
212
- pvcsWeightByPoint
213
- certsToRemove
203
+ , pvcsWeightByPoint = prunePerasWeightSnapshot slot pvcsWeightByPoint
214
204
}
215
205
where
216
- (certsToRemove , certsToKeep) =
206
+ (_ , certsToKeep) =
217
207
Map. partition isTooOld pvcsCerts
218
208
isTooOld cert =
219
209
pointSlot (perasCertBoostedBlock cert) < NotOrigin slot
You can’t perform that action at this time.
0 commit comments