github.com/koko1123/flow-go-1@v0.29.6/module/buffer/pending_cluster_blocks.go (about) 1 package buffer 2 3 import ( 4 "github.com/koko1123/flow-go-1/model/cluster" 5 "github.com/koko1123/flow-go-1/model/flow" 6 ) 7 8 type PendingClusterBlocks struct { 9 backend *backend 10 } 11 12 func NewPendingClusterBlocks() *PendingClusterBlocks { 13 b := &PendingClusterBlocks{backend: newBackend()} 14 return b 15 } 16 17 func (b *PendingClusterBlocks) Add(originID flow.Identifier, block *cluster.Block) bool { 18 return b.backend.add(originID, block.Header, block.Payload) 19 } 20 21 func (b *PendingClusterBlocks) ByID(blockID flow.Identifier) (flow.Slashable[cluster.Block], bool) { 22 item, ok := b.backend.byID(blockID) 23 if !ok { 24 return flow.Slashable[cluster.Block]{}, false 25 } 26 27 block := flow.Slashable[cluster.Block]{ 28 OriginID: item.originID, 29 Message: &cluster.Block{ 30 Header: item.header, 31 Payload: item.payload.(*cluster.Payload), 32 }, 33 } 34 35 return block, true 36 } 37 38 func (b *PendingClusterBlocks) ByParentID(parentID flow.Identifier) ([]flow.Slashable[cluster.Block], bool) { 39 items, ok := b.backend.byParentID(parentID) 40 if !ok { 41 return nil, false 42 } 43 44 blocks := make([]flow.Slashable[cluster.Block], 0, len(items)) 45 for _, item := range items { 46 block := flow.Slashable[cluster.Block]{ 47 OriginID: item.originID, 48 Message: &cluster.Block{ 49 Header: item.header, 50 Payload: item.payload.(*cluster.Payload), 51 }, 52 } 53 blocks = append(blocks, block) 54 } 55 56 return blocks, true 57 } 58 59 func (b *PendingClusterBlocks) DropForParent(parentID flow.Identifier) { 60 b.backend.dropForParent(parentID) 61 } 62 63 // PruneByView prunes any pending cluster blocks with views less or equal to the given view. 64 func (b *PendingClusterBlocks) PruneByView(view uint64) { 65 b.backend.pruneByView(view) 66 } 67 68 func (b *PendingClusterBlocks) Size() uint { 69 return b.backend.size() 70 }