github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/vecmt/no_cheaters.go (about) 1 package vecmt 2 3 import ( 4 "errors" 5 6 "github.com/unicornultrafoundation/go-helios/hash" 7 ) 8 9 // NoCheaters excludes events which are observed by selfParents as cheaters. 10 // Called by emitter to exclude cheater's events from potential parents list. 11 func (vi *Index) NoCheaters(selfParent *hash.Event, options hash.Events) hash.Events { 12 if selfParent == nil { 13 return options 14 } 15 vi.InitBranchesInfo() 16 17 if !vi.Engine.AtLeastOneFork() { 18 return options 19 } 20 21 // no need to merge, because every branch is marked by IsForkDetected if fork is observed 22 highest := vi.Base.GetHighestBefore(*selfParent) 23 filtered := make(hash.Events, 0, len(options)) 24 for _, id := range options { 25 e := vi.getEvent(id) 26 if e == nil { 27 vi.crit(errors.New("event not found")) 28 } 29 if !highest.Get(vi.validatorIdxs[e.Creator()]).IsForkDetected() { 30 filtered.Add(id) 31 } 32 } 33 return filtered 34 }