-
Notifications
You must be signed in to change notification settings - Fork 199
/
interface.go
165 lines (147 loc) · 6.37 KB
/
interface.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package sharding
import (
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/epochStart"
)
// Coordinator defines what a shard state coordinator should hold
type Coordinator interface {
NumberOfShards() uint32
ComputeId(address state.AddressContainer) uint32
SelfId() uint32
SameShard(firstAddress, secondAddress state.AddressContainer) bool
CommunicationIdentifier(destShardID uint32) string
IsInterfaceNil() bool
}
// Validator defines a node that can be allocated to a shard for participation in a consensus group as validator
// or block proposer
type Validator interface {
PubKey() []byte
Chances() uint32
Index() uint32
}
// NodesCoordinator defines the behaviour of a struct able to do validator group selection
type NodesCoordinator interface {
NodesCoordinatorHelper
PublicKeysSelector
ComputeConsensusGroup(randomness []byte, round uint64, shardId uint32, epoch uint32) (validatorsGroup []Validator, err error)
GetValidatorWithPublicKey(publicKey []byte, epoch uint32) (validator Validator, shardId uint32, err error)
LoadState(key []byte) error
GetSavedStateKey() []byte
ShardIdForEpoch(epoch uint32) (uint32, error)
GetConsensusWhitelistedNodes(epoch uint32) (map[string]struct{}, error)
ConsensusGroupSize(uint32) int
GetNumTotalEligible() uint64
IsInterfaceNil() bool
}
// EpochStartEventNotifier provides Register and Unregister functionality for the end of epoch events
type EpochStartEventNotifier interface {
RegisterHandler(handler epochStart.ActionHandler)
UnregisterHandler(handler epochStart.ActionHandler)
}
// PublicKeysSelector allows retrieval of eligible validators public keys
type PublicKeysSelector interface {
GetValidatorsIndexes(publicKeys []string, epoch uint32) ([]uint64, error)
GetAllEligibleValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetAllWaitingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetAllLeavingValidatorsPublicKeys(epoch uint32) ([][]byte, error)
GetConsensusValidatorsPublicKeys(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error)
GetOwnPublicKey() []byte
}
// EpochHandler defines what a component which handles current epoch should be able to do
type EpochHandler interface {
MetaEpoch() uint32
IsInterfaceNil() bool
}
// ArgsUpdateNodes holds the parameters required by the shuffler to generate a new nodes configuration
type ArgsUpdateNodes struct {
Eligible map[uint32][]Validator
Waiting map[uint32][]Validator
NewNodes []Validator
Leaving []Validator
Rand []byte
NbShards uint32
}
// NodesShuffler provides shuffling functionality for nodes
type NodesShuffler interface {
UpdateParams(numNodesShard uint32, numNodesMeta uint32, hysteresis float32, adaptivity bool)
UpdateNodeLists(args ArgsUpdateNodes) (map[uint32][]Validator, map[uint32][]Validator, []Validator)
IsInterfaceNil() bool
}
// NodesCoordinatorHelper provides polymorphism functionality for nodesCoordinator
type NodesCoordinatorHelper interface {
ValidatorsWeights(validators []Validator) ([]uint32, error)
ComputeLeaving(allValidators []*state.ShardValidatorInfo) ([]Validator, error)
GetChance(uint32) uint32
}
//PeerAccountListAndRatingHandler provides Rating Computation Capabilites for the Nodes Coordinator and ValidatorStatistics
type PeerAccountListAndRatingHandler interface {
//GetChance returns the chances for the the rating
GetChance(uint32) uint32
//GetStartRating gets the start rating values
GetStartRating() uint32
//GetSignedBlocksThreshold gets the threshold for the minimum signed blocks
GetSignedBlocksThreshold() float32
//ComputeIncreaseProposer computes the new rating for the increaseLeader
ComputeIncreaseProposer(shardId uint32, currentRating uint32) uint32
//ComputeDecreaseProposer computes the new rating for the decreaseLeader
ComputeDecreaseProposer(shardId uint32, currentRating uint32, consecutiveMisses uint32) uint32
//RevertIncreaseValidator computes the new rating if a revert for increaseProposer should be done
RevertIncreaseValidator(shardId uint32, currentRating uint32, nrReverts uint32) uint32
//ComputeIncreaseValidator computes the new rating for the increaseValidator
ComputeIncreaseValidator(shardId uint32, currentRating uint32) uint32
//ComputeDecreaseValidator computes the new rating for the decreaseValidator
ComputeDecreaseValidator(shardId uint32, currentRating uint32) uint32
IsInterfaceNil() bool
}
//ChanceComputer provides chance computation capabilities based on a rating
type ChanceComputer interface {
//GetChance returns the chances for the the rating
GetChance(uint32) uint32
//IsInterfaceNil verifies if the interface is nil
IsInterfaceNil() bool
}
//Cacher provides the capabilities needed to store and retrieve information needed in the NodesCoordinator
type Cacher interface {
// Put adds a value to the cache. Returns true if an eviction occurred.
Put(key []byte, value interface{}) (evicted bool)
// Get looks up a key's value from the cache.
Get(key []byte) (value interface{}, ok bool)
}
// ShuffledOutHandler defines the methods needed for the computation of a shuffled out event
type ShuffledOutHandler interface {
Process(newShardID uint32) error
RegisterHandler(handler func(newShardID uint32))
CurrentShardID() uint32
IsInterfaceNil() bool
}
// RandomSelector selects randomly a subset of elements from a set of data
type RandomSelector interface {
Select(randSeed []byte, sampleSize uint32) ([]uint32, error)
IsInterfaceNil() bool
}
// EpochStartActionHandler defines the action taken on epoch start event
type EpochStartActionHandler interface {
EpochStartAction(hdr data.HeaderHandler)
EpochStartPrepare(metaHdr data.HeaderHandler, body data.BodyHandler)
NotifyOrder() uint32
}
// GenesisNodesSetupHandler returns the genesis nodes info
type GenesisNodesSetupHandler interface {
InitialNodesInfoForShard(shardId uint32) ([]GenesisNodeInfoHandler, []GenesisNodeInfoHandler, error)
InitialNodesInfo() (map[uint32][]GenesisNodeInfoHandler, map[uint32][]GenesisNodeInfoHandler)
GetStartTime() int64
GetRoundDuration() uint64
GetChainId() string
GetShardConsensusGroupSize() uint32
GetMetaConsensusGroupSize() uint32
NumberOfShards() uint32
IsInterfaceNil() bool
}
// GenesisNodeInfoHandler defines the public methods for the genesis nodes info
type GenesisNodeInfoHandler interface {
AssignedShard() uint32
Address() []byte
PubKey() []byte
IsInterfaceNil() bool
}