-
Notifications
You must be signed in to change notification settings - Fork 177
/
bft.go
42 lines (36 loc) · 1.62 KB
/
bft.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
package operation
import (
"errors"
"fmt"
"github.com/dgraph-io/badger/v2"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/storage"
)
// PurgeBlocklist removes the set of blocked nodes IDs from the data base.
// If no corresponding entry exists, this function is a no-op.
// No errors are expected during normal operations.
// TODO: TEMPORARY manual override for adding node IDs to list of ejected nodes, applies to networking layer only
func PurgeBlocklist() func(*badger.Txn) error {
return func(tx *badger.Txn) error {
err := remove(makePrefix(blockedNodeIDs))(tx)
if err != nil && !errors.Is(err, storage.ErrNotFound) {
return fmt.Errorf("enexpected error while purging blocklist: %w", err)
}
return nil
}
}
// PersistBlocklist writes the set of blocked nodes IDs into the data base.
// If an entry already exists, it is overwritten; otherwise a new entry is created.
// No errors are expected during normal operations.
//
// TODO: TEMPORARY manual override for adding node IDs to list of ejected nodes, applies to networking layer only
func PersistBlocklist(blocklist map[flow.Identifier]struct{}) func(*badger.Txn) error {
return upsert(makePrefix(blockedNodeIDs), blocklist)
}
// RetrieveBlocklist reads the set of blocked node IDs from the data base.
// Returns `storage.ErrNotFound` error in case no respective data base entry is present.
//
// TODO: TEMPORARY manual override for adding node IDs to list of ejected nodes, applies to networking layer only
func RetrieveBlocklist(blocklist *map[flow.Identifier]struct{}) func(*badger.Txn) error {
return retrieve(makePrefix(blockedNodeIDs), blocklist)
}