github.com/koko1123/flow-go-1@v0.29.6/module/mempool/stdmap/guarantees.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package stdmap 4 5 import ( 6 "github.com/koko1123/flow-go-1/model/flow" 7 ) 8 9 // Guarantees implements the collections memory pool of the consensus nodes, 10 // used to store collection guarantees and to generate block payloads. 11 type Guarantees struct { 12 *Backend 13 } 14 15 // NewGuarantees creates a new memory pool for collection guarantees. 16 func NewGuarantees(limit uint) (*Guarantees, error) { 17 g := &Guarantees{ 18 Backend: NewBackend(WithLimit(limit)), 19 } 20 21 return g, nil 22 } 23 24 // Add adds a collection guarantee guarantee to the mempool. 25 func (g *Guarantees) Add(guarantee *flow.CollectionGuarantee) bool { 26 return g.Backend.Add(guarantee) 27 } 28 29 // ByID returns the collection guarantee with the given ID from the mempool. 30 func (g *Guarantees) ByID(collID flow.Identifier) (*flow.CollectionGuarantee, bool) { 31 entity, exists := g.Backend.ByID(collID) 32 if !exists { 33 return nil, false 34 } 35 guarantee := entity.(*flow.CollectionGuarantee) 36 return guarantee, true 37 } 38 39 // All returns all collection guarantees from the mempool. 40 func (g *Guarantees) All() []*flow.CollectionGuarantee { 41 entities := g.Backend.All() 42 guarantees := make([]*flow.CollectionGuarantee, 0, len(entities)) 43 for _, entity := range entities { 44 guarantees = append(guarantees, entity.(*flow.CollectionGuarantee)) 45 } 46 return guarantees 47 }