-
Notifications
You must be signed in to change notification settings - Fork 178
/
cluster.go
50 lines (40 loc) · 2.34 KB
/
cluster.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
package operation
import (
"github.com/dgraph-io/badger/v2"
"github.com/onflow/flow-go/model/flow"
)
// This file implements storage functions for chain state book-keeping of
// collection node cluster consensus. In contrast to the corresponding functions
// for regular consensus, these functions include the cluster ID in order to
// support storing multiple chains, for example during epoch switchover.
// IndexClusterBlockHeight inserts a block number to block ID mapping for
// the given cluster.
func IndexClusterBlockHeight(clusterID flow.ChainID, number uint64, blockID flow.Identifier) func(*badger.Txn) error {
return insert(makePrefix(codeFinalizedCluster, clusterID, number), blockID)
}
// LookupClusterBlockHeight retrieves a block ID by number for the given cluster
func LookupClusterBlockHeight(clusterID flow.ChainID, number uint64, blockID *flow.Identifier) func(*badger.Txn) error {
return retrieve(makePrefix(codeFinalizedCluster, clusterID, number), blockID)
}
// InsertClusterFinalizedHeight inserts the finalized boundary for the given cluster.
func InsertClusterFinalizedHeight(clusterID flow.ChainID, number uint64) func(*badger.Txn) error {
return insert(makePrefix(codeClusterHeight, clusterID), number)
}
// UpdateClusterFinalizedHeight updates the finalized boundary for the given cluster.
func UpdateClusterFinalizedHeight(clusterID flow.ChainID, number uint64) func(*badger.Txn) error {
return update(makePrefix(codeClusterHeight, clusterID), number)
}
// RetrieveClusterFinalizedHeight retrieves the finalized boundary for the given cluster.
func RetrieveClusterFinalizedHeight(clusterID flow.ChainID, number *uint64) func(*badger.Txn) error {
return retrieve(makePrefix(codeClusterHeight, clusterID), number)
}
// IndexCollectionReference inserts the reference block ID for a cluster
// block payload (ie. collection) keyed by the cluster block ID
func IndexCollectionReference(clusterBlockID, refID flow.Identifier) func(*badger.Txn) error {
return insert(makePrefix(codeCollectionReference, clusterBlockID), refID)
}
// LookupCollectionReference looks up the reference block ID for a cluster
// block payload (ie. collection) keyed by the cluster block ID.
func LookupCollectionReference(clusterBlockID flow.Identifier, refID *flow.Identifier) func(*badger.Txn) error {
return retrieve(makePrefix(codeCollectionReference, clusterBlockID), refID)
}