forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverridden_manager.go
89 lines (69 loc) · 2.94 KB
/
overridden_manager.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package node
import (
"fmt"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/set"
)
var _ validators.Manager = (*overriddenManager)(nil)
// newOverriddenManager returns a Manager that overrides of all calls to the
// underlying Manager to only operate on the validators in [subnetID].
func newOverriddenManager(subnetID ids.ID, manager validators.Manager) *overriddenManager {
return &overriddenManager{
subnetID: subnetID,
manager: manager,
}
}
// overriddenManager is a wrapper around a Manager that overrides of all calls
// to the underlying Manager to only operate on the validators in [subnetID].
// subnetID here is typically the primary network ID, as it has the superset of
// all subnet validators.
type overriddenManager struct {
manager validators.Manager
subnetID ids.ID
}
func (o *overriddenManager) AddStaker(_ ids.ID, nodeID ids.NodeID, pk *bls.PublicKey, txID ids.ID, weight uint64) error {
return o.manager.AddStaker(o.subnetID, nodeID, pk, txID, weight)
}
func (o *overriddenManager) AddWeight(_ ids.ID, nodeID ids.NodeID, weight uint64) error {
return o.manager.AddWeight(o.subnetID, nodeID, weight)
}
func (o *overriddenManager) GetWeight(_ ids.ID, nodeID ids.NodeID) uint64 {
return o.manager.GetWeight(o.subnetID, nodeID)
}
func (o *overriddenManager) GetValidator(_ ids.ID, nodeID ids.NodeID) (*validators.Validator, bool) {
return o.manager.GetValidator(o.subnetID, nodeID)
}
func (o *overriddenManager) SubsetWeight(_ ids.ID, nodeIDs set.Set[ids.NodeID]) (uint64, error) {
return o.manager.SubsetWeight(o.subnetID, nodeIDs)
}
func (o *overriddenManager) RemoveWeight(_ ids.ID, nodeID ids.NodeID, weight uint64) error {
return o.manager.RemoveWeight(o.subnetID, nodeID, weight)
}
func (o *overriddenManager) Count(ids.ID) int {
return o.manager.Count(o.subnetID)
}
func (o *overriddenManager) TotalWeight(ids.ID) (uint64, error) {
return o.manager.TotalWeight(o.subnetID)
}
func (o *overriddenManager) Sample(_ ids.ID, size int) ([]ids.NodeID, error) {
return o.manager.Sample(o.subnetID, size)
}
func (o *overriddenManager) GetMap(ids.ID) map[ids.NodeID]*validators.GetValidatorOutput {
return o.manager.GetMap(o.subnetID)
}
func (o *overriddenManager) RegisterCallbackListener(listener validators.ManagerCallbackListener) {
o.manager.RegisterCallbackListener(listener)
}
func (o *overriddenManager) RegisterSetCallbackListener(_ ids.ID, listener validators.SetCallbackListener) {
o.manager.RegisterSetCallbackListener(o.subnetID, listener)
}
func (o *overriddenManager) String() string {
return fmt.Sprintf("Overridden Validator Manager (SubnetID = %s): %s", o.subnetID, o.manager)
}
func (o *overriddenManager) GetValidatorIDs(ids.ID) []ids.NodeID {
return o.manager.GetValidatorIDs(o.subnetID)
}