Skip to content

Commit f659eda

Browse files
committed
simulation: prune delivery times for IBs already voted on
1 parent a73fe18 commit f659eda

File tree

1 file changed

+10
-4
lines changed
  • simulation/src/LeiosProtocol/Short

1 file changed

+10
-4
lines changed

simulation/src/LeiosProtocol/Short/Node.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ data LeiosNodeState m = LeiosNodeState
110110
, relayVoteState :: !(RelayVoteState m)
111111
, prunedVoteStateToVar :: !(TVar m SlotNo)
112112
-- ^ 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.
114116
, taskQueue :: !(TaskMultiQueue LeiosNodeTask m)
115117
, waitingForRBVar :: !(TVar m (Map (HeaderHash RankingBlock) [STM m ()]))
116118
-- ^ waiting for RB block itself to be validated.
@@ -573,9 +575,10 @@ pruneExpiredVotes ::
573575
LeiosNodeConfig ->
574576
LeiosNodeState m ->
575577
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)
577579
where
578580
go p = do
581+
let pruneIBDeliveryTo = succ $ snd (stageRangeOf @p leios p Short.Propose)
579582
let pruneTo = succ (lastVoteSend leios p)
580583
_ <- waitNextSlot slotConfig (succ (lastVoteRecv leios p))
581584
atomically $ do
@@ -584,6 +587,8 @@ pruneExpiredVotes _tracer LeiosNodeConfig{leios, slotConfig} st = go (toEnum 0)
584587
let voteSlot = (snd voteEntry.value).slot
585588
in voteSlot >= pruneTo
586589
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
587592
go (succ p)
588593

589594
computeLedgerStateThread ::
@@ -623,10 +628,11 @@ computeLedgerStateThread _tracer _cfg st = forever $ do
623628

624629
adoptIB :: MonadSTM m => LeiosNodeState m -> InputBlock -> UTCTime -> STM m ()
625630
adoptIB leiosState ib deliveryTime = do
631+
let !ibSlot = ib.header.slot
626632
-- NOTE: voting relies on delivery times for IBs
627633
modifyTVar'
628634
leiosState.ibDeliveryTimesVar
629-
(Map.insertWith min ib.id deliveryTime)
635+
(Map.insertWith (\(_, x) (s, y) -> (,) s $! min x y) ib.id (ibSlot, deliveryTime))
630636

631637
-- TODO: likely needs optimization, although EBs also grow slowly.
632638
modifyTVar' leiosState.ibsNeededForEBVar (Map.map (Set.delete ib.id))
@@ -826,7 +832,7 @@ mkBuffersView cfg st = BuffersView{..}
826832
$ buffer
827833
receivedByCheck slot =
828834
filter
829-
( maybe False (<= slotTime cfg.slotConfig slot)
835+
( maybe False ((<= slotTime cfg.slotConfig slot) . snd)
830836
. flip Map.lookup times
831837
)
832838
validInputBlocks q = receivedByCheck q.receivedBy $ generatedCheck q.generatedBetween

0 commit comments

Comments
 (0)