-
Notifications
You must be signed in to change notification settings - Fork 175
/
state.go
37 lines (30 loc) · 1.09 KB
/
state.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
package cluster
import (
"fmt"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/cluster"
"github.com/onflow/flow-go/storage"
)
// FindLatest retrieves the latest finalized header and all of its pending
// children. These pending children have been verified by the compliance layer
// but are NOT guaranteed to have been verified by HotStuff. They MUST be
// validated by HotStuff during the recovery process.
func FindLatest(state cluster.State, headers storage.Headers) (*flow.Header, []*flow.Header, error) {
finalized, err := state.Final().Head()
if err != nil {
return nil, nil, fmt.Errorf("could not get finalized header: %w", err)
}
pendingIDs, err := state.Final().Pending()
if err != nil {
return nil, nil, fmt.Errorf("could not get pending children: %w", err)
}
pending := make([]*flow.Header, 0, len(pendingIDs))
for _, pendingID := range pendingIDs {
header, err := headers.ByBlockID(pendingID)
if err != nil {
return nil, nil, fmt.Errorf("could not find pending child: %w", err)
}
pending = append(pending, header)
}
return finalized, pending, nil
}