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