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