-
Notifications
You must be signed in to change notification settings - Fork 177
/
incorporated_result_seals.go
41 lines (35 loc) · 1.13 KB
/
incorporated_result_seals.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
package ejectors
import (
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/storage"
)
// LatestIncorporatedResultSeal is a mempool ejector for incorporated result
// seals that ejects newest-first.
// NOTE: should be initialized with its own headers instance with cache size
// equal to the mempool size.
type LatestIncorporatedResultSeal struct {
headers storage.Headers
}
func NewLatestIncorporatedResultSeal(headers storage.Headers) *LatestIncorporatedResultSeal {
ejector := &LatestIncorporatedResultSeal{
headers: headers,
}
return ejector
}
func (ls *LatestIncorporatedResultSeal) Eject(entities map[flow.Identifier]flow.Entity) (flow.Identifier, flow.Entity) {
maxHeight := uint64(0)
maxID := flow.ZeroID
for id, entity := range entities {
irSeal := entity.(*flow.IncorporatedResultSeal)
block, err := ls.headers.ByBlockID(irSeal.Seal.BlockID)
if err != nil {
// eject seals first, whose block is not even known (which are presumably newer than any other entity)
return id, entity
}
if block.Height >= maxHeight {
maxHeight = block.Height
maxID = id
}
}
return maxID, entities[maxID]
}