Skip to content

Commit 7d10a4e

Browse files
nbacqueyneilmayhew
authored andcommitted
Fix dropElemsAt implementation
1 parent 3c2c434 commit 7d10a4e

File tree

1 file changed

+4
-4
lines changed
  • ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/Genesis/Tests

1 file changed

+4
-4
lines changed

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/Genesis/Tests/Uniform.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Data.List (intercalate, sort, uncons)
2323
import qualified Data.List.NonEmpty as NE
2424
import qualified Data.Map.Strict as Map
2525
import Data.Maybe (fromMaybe, mapMaybe)
26+
import qualified Data.Set as Set
2627
import Data.Word (Word64)
2728
import GHC.Stack (HasCallStack)
2829
import Ouroboros.Consensus.Block.Abstract (WithOrigin (NotOrigin))
@@ -239,10 +240,9 @@ prop_leashingAttackStalling =
239240
pure $ dropElemsAt ps is
240241

241242
dropElemsAt :: [a] -> [Int] -> [a]
242-
dropElemsAt xs [] = xs
243-
dropElemsAt xs (i:is) =
244-
let (ys, zs) = splitAt i xs
245-
in ys ++ dropElemsAt (drop 1 zs) is
243+
dropElemsAt xs is' =
244+
let is = Set.fromList is'
245+
in map fst $ filter (\(_, i) -> not $ i `Set.member` is) (zip xs [0..])
246246

247247
-- | Test that the leashing attacks do not delay the immutable tip after. The
248248
-- immutable tip needs to be advanced enough when the honest peer has offered

0 commit comments

Comments
 (0)