@@ -110,7 +110,9 @@ data LeiosNodeState m = LeiosNodeState
110
110
, relayVoteState :: ! (RelayVoteState m )
111
111
, prunedVoteStateToVar :: ! (TVar m SlotNo )
112
112
-- ^ TODO: refactor into RelayState.
113
- , ibDeliveryTimesVar :: ! (TVar m (Map InputBlockId UTCTime ))
113
+ , ibDeliveryTimesVar :: ! (TVar m (Map InputBlockId (SlotNo , UTCTime )))
114
+ -- ^ records time we received the input block.
115
+ -- Also stores the SlotNo of the IB to ease pruning.
114
116
, taskQueue :: ! (TaskMultiQueue LeiosNodeTask m )
115
117
, waitingForRBVar :: ! (TVar m (Map (HeaderHash RankingBlock ) [STM m () ]))
116
118
-- ^ waiting for RB block itself to be validated.
@@ -573,9 +575,10 @@ pruneExpiredVotes ::
573
575
LeiosNodeConfig ->
574
576
LeiosNodeState m ->
575
577
m ()
576
- pruneExpiredVotes _tracer LeiosNodeConfig {leios, slotConfig} st = go (toEnum 0 )
578
+ pruneExpiredVotes _tracer LeiosNodeConfig {leios = leios @ LeiosConfig {pipeline = _ :: SingPipeline p } , slotConfig } st = go (toEnum 0 )
577
579
where
578
580
go p = do
581
+ let pruneIBDeliveryTo = succ $ snd (stageRangeOf @ p leios p Short. Propose )
579
582
let pruneTo = succ (lastVoteSend leios p)
580
583
_ <- waitNextSlot slotConfig (succ (lastVoteRecv leios p))
581
584
atomically $ do
@@ -584,6 +587,8 @@ pruneExpiredVotes _tracer LeiosNodeConfig{leios, slotConfig} st = go (toEnum 0)
584
587
let voteSlot = (snd voteEntry. value). slot
585
588
in voteSlot >= pruneTo
586
589
writeTVar st. prunedVoteStateToVar $! pruneTo
590
+ -- delivery times for IBs are only needed to vote, so they can be pruned too.
591
+ modifyTVar' st. ibDeliveryTimesVar $ Map. filter $ \ (slot, _) -> slot >= pruneIBDeliveryTo
587
592
go (succ p)
588
593
589
594
computeLedgerStateThread ::
@@ -623,10 +628,11 @@ computeLedgerStateThread _tracer _cfg st = forever $ do
623
628
624
629
adoptIB :: MonadSTM m => LeiosNodeState m -> InputBlock -> UTCTime -> STM m ()
625
630
adoptIB leiosState ib deliveryTime = do
631
+ let ! ibSlot = ib. header. slot
626
632
-- NOTE: voting relies on delivery times for IBs
627
633
modifyTVar'
628
634
leiosState. ibDeliveryTimesVar
629
- (Map. insertWith min ib. id deliveryTime)
635
+ (Map. insertWith ( \ (_, x) (s, y) -> (,) s $! min x y) ib. id (ibSlot, deliveryTime) )
630
636
631
637
-- TODO: likely needs optimization, although EBs also grow slowly.
632
638
modifyTVar' leiosState. ibsNeededForEBVar (Map. map (Set. delete ib. id ))
@@ -826,7 +832,7 @@ mkBuffersView cfg st = BuffersView{..}
826
832
$ buffer
827
833
receivedByCheck slot =
828
834
filter
829
- ( maybe False (<= slotTime cfg. slotConfig slot)
835
+ ( maybe False (( <= slotTime cfg. slotConfig slot) . snd )
830
836
. flip Map. lookup times
831
837
)
832
838
validInputBlocks q = receivedByCheck q. receivedBy $ generatedCheck q. generatedBetween
0 commit comments