Skip to content

Commit

Permalink
consensus: handle EBBs in rewindHeaderState
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrisby committed Feb 24, 2020
1 parent ccc8eb1 commit d1b4d92
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ouroboros-consensus/src/Ouroboros/Consensus/HeaderValidation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,22 @@ rewindHeaderState cfg p HeaderState{..} = do
chainState' <- rewindChainState (configConsensus cfg) headerStateChain p
return $ HeaderState {
headerStateChain = chainState'
, headerStateTips = Seq.dropWhileR rolledBack headerStateTips
, headerStateTips = checkEBB $ Seq.dropWhileR tooNew headerStateTips
, headerStateAnchor = headerStateAnchor
}
where
rolledBack :: AnnTip blk -> Bool
rolledBack t = annTipPoint t > p
tooNew :: AnnTip blk -> Bool
tooNew t = At (annTipSlotNo t) > pointSlot p

-- drops one more block if the target's successor shares its slot (this can
-- happen when the target is an EBB)
checkEBB :: StrictSeq (AnnTip blk) -> StrictSeq (AnnTip blk)
checkEBB tips = case tips of
-- t' and t have the same slot, t' is the target
tips'@(_ Seq.:|> t') Seq.:|> t | At (annTipSlotNo t) == pointSlot p
, annTipPoint t' == p -> tips'
-- either the target is the tip, or the target has been trimmed off
_ -> tips

{-------------------------------------------------------------------------------
Validate header envelope
Expand Down

0 comments on commit d1b4d92

Please sign in to comment.