Skip to content

Commit 86d8135

Browse files
committed
PerasWeightSnapshot: minimize API
1 parent 4216b1e commit 86d8135

File tree

2 files changed

+9
-23
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus

2 files changed

+9
-23
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Peras/Weight.hs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Ouroboros.Consensus.Peras.Weight
1212
, mkPerasWeightSnapshot
1313
, perasWeightSnapshotToList
1414
, addToPerasWeightSnapshot
15-
, removeFromPerasWeightSnapshot
15+
, prunePerasWeightSnapshot
1616
, weightBoostOfPoint
1717
, weightBoostOfFragment
1818
) where
@@ -57,19 +57,15 @@ addToPerasWeightSnapshot ::
5757
addToPerasWeightSnapshot pt weight =
5858
PerasWeightSnapshot . Map.insertWith (<>) pt weight . getPerasWeightSnapshot
5959

60-
removeFromPerasWeightSnapshot ::
61-
StandardHash blk =>
62-
Point blk ->
63-
PerasWeight ->
60+
prunePerasWeightSnapshot ::
61+
SlotNo ->
6462
PerasWeightSnapshot blk ->
6563
PerasWeightSnapshot blk
66-
removeFromPerasWeightSnapshot pt (PerasWeight weight) =
67-
PerasWeightSnapshot . Map.update subtractWeight pt . getPerasWeightSnapshot
64+
prunePerasWeightSnapshot slot =
65+
PerasWeightSnapshot . Map.dropWhileAntitone isTooOld . getPerasWeightSnapshot
6866
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
7369

7470
weightBoostOfPoint ::
7571
forall blk.

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/PerasCertDB/Impl.hs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module Ouroboros.Consensus.Storage.PerasCertDB.Impl
2121
) where
2222

2323
import Control.Tracer (Tracer, nullTracer, traceWith)
24-
import Data.Foldable as Foldable (foldl')
2524
import Data.Kind (Type)
2625
import Data.Map.Strict (Map)
2726
import qualified Data.Map.Strict as Map
@@ -201,19 +200,10 @@ implGarbageCollect PerasCertDbEnv{pcdbVolatileState} slot =
201200
gc PerasVolatileCertState{pvcsCerts, pvcsWeightByPoint} =
202201
PerasVolatileCertState
203202
{ 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
214204
}
215205
where
216-
(certsToRemove, certsToKeep) =
206+
(_, certsToKeep) =
217207
Map.partition isTooOld pvcsCerts
218208
isTooOld cert =
219209
pointSlot (perasCertBoostedBlock cert) < NotOrigin slot

0 commit comments

Comments
 (0)