github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/mempool/stdmap/queues.go (about) 1 package stdmap 2 3 import ( 4 "fmt" 5 6 "github.com/onflow/flow-go/model/flow" 7 "github.com/onflow/flow-go/module/mempool" 8 "github.com/onflow/flow-go/module/mempool/queue" 9 _ "github.com/onflow/flow-go/utils/binstat" 10 ) 11 12 type Queues struct { 13 *Backend 14 } 15 16 // QueuesBackdata is mempool map for ingestion.Queues (head Node ID -> Queues) 17 type QueuesBackdata struct { 18 mempool.BackData 19 } 20 21 func NewQueues() *Queues { 22 return &Queues{NewBackend(WithEject(EjectPanic))} 23 } 24 25 func (b *QueuesBackdata) ByID(queueID flow.Identifier) (*queue.Queue, bool) { 26 entity, exists := b.BackData.ByID(queueID) 27 if !exists { 28 return nil, false 29 } 30 queue := entity.(*queue.Queue) 31 return queue, true 32 } 33 34 func (b *QueuesBackdata) All() []*queue.Queue { 35 entities := b.BackData.All() 36 37 queues := make([]*queue.Queue, len(entities)) 38 i := 0 39 for _, entity := range entities { 40 queue, ok := entity.(*queue.Queue) 41 if !ok { 42 panic(fmt.Sprintf("invalid entity in queue mempool (%T)", entity)) 43 } 44 queues[i] = queue 45 i++ 46 } 47 return queues 48 } 49 50 func (b *Queues) Add(queue *queue.Queue) bool { 51 return b.Backend.Add(queue) 52 } 53 54 func (b *Queues) Get(queueID flow.Identifier) (*queue.Queue, bool) { 55 backdata := &QueuesBackdata{b.backData} 56 return backdata.ByID(queueID) 57 } 58 59 func (b *Queues) Run(f func(backdata *QueuesBackdata) error) error { 60 //bs1 := binstat.EnterTime(binstat.BinStdmap + ".w_lock.(Queues)Run") 61 b.Lock() 62 //binstat.Leave(bs1) 63 64 //bs2 := binstat.EnterTime(binstat.BinStdmap + ".inlock.(Queues)Run") 65 defer b.Unlock() 66 err := f(&QueuesBackdata{b.backData}) 67 //binstat.Leave(bs2) 68 69 if err != nil { 70 return err 71 } 72 return nil 73 }