-
Notifications
You must be signed in to change notification settings - Fork 10
/
pending_list.go
63 lines (53 loc) · 1.21 KB
/
pending_list.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
// Copyright (c) 2020 The Meter.io developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package consensus
type PendingList struct {
messages map[uint32]consensusMsgInfo
lowest uint32
}
func NewPendingList() *PendingList {
return &PendingList{
messages: make(map[uint32]consensusMsgInfo),
lowest: 0,
}
}
func (p *PendingList) Add(mi *consensusMsgInfo) {
var height uint32 // Query height
switch msg := mi.Msg.(type) {
case *PMProposalMessage:
height = msg.ParentHeight
case *PMNewViewMessage:
height = msg.QCHeight
default:
return
}
if height < p.lowest {
p.lowest = height
}
p.messages[height] = *mi
}
func (p *PendingList) GetLowestHeight() uint32 {
return p.lowest
}
func (p *PendingList) Len() int {
return len(p.messages)
}
func (p *PendingList) CleanUpTo(height uint32) {
if height < p.lowest {
return
}
for key, _ := range p.messages {
if key <= height {
delete(p.messages, key)
}
}
p.lowest = height
}
// clean all the pending messages
func (p *PendingList) CleanAll() {
for key := range p.messages {
delete(p.messages, key)
}
p.lowest = 0
}