/
nodesCoordinatorFactory.go
162 lines (146 loc) · 6.11 KB
/
nodesCoordinatorFactory.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
package integrationTests
import (
"fmt"
"github.com/ElrondNetwork/elrond-go-core/data/endProcess"
"github.com/ElrondNetwork/elrond-go-core/hashing"
"github.com/ElrondNetwork/elrond-go/integrationTests/mock"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/sharding/nodesCoordinator"
"github.com/ElrondNetwork/elrond-go/storage"
"github.com/ElrondNetwork/elrond-go/testscommon"
"github.com/ElrondNetwork/elrond-go/testscommon/nodeTypeProviderMock"
vic "github.com/ElrondNetwork/elrond-go/testscommon/validatorInfoCacher"
)
// ArgIndexHashedNodesCoordinatorFactory -
type ArgIndexHashedNodesCoordinatorFactory struct {
nodesPerShard int
nbMetaNodes int
shardConsensusGroupSize int
metaConsensusGroupSize int
shardId uint32
nbShards int
validatorsMap map[uint32][]nodesCoordinator.Validator
waitingMap map[uint32][]nodesCoordinator.Validator
keyIndex int
cp *CryptoParams
epochStartSubscriber nodesCoordinator.EpochStartEventNotifier
hasher hashing.Hasher
consensusGroupCache nodesCoordinator.Cacher
bootStorer storage.Storer
}
// IndexHashedNodesCoordinatorFactory -
type IndexHashedNodesCoordinatorFactory struct {
}
// CreateNodesCoordinator -
func (tpn *IndexHashedNodesCoordinatorFactory) CreateNodesCoordinator(arg ArgIndexHashedNodesCoordinatorFactory) nodesCoordinator.NodesCoordinator {
keys := arg.cp.Keys[arg.shardId][arg.keyIndex]
pubKeyBytes, _ := keys.Pk.ToByteArray()
nodeShufflerArgs := &nodesCoordinator.NodesShufflerArgs{
NodesShard: uint32(arg.nodesPerShard),
NodesMeta: uint32(arg.nbMetaNodes),
Hysteresis: hysteresis,
Adaptivity: adaptivity,
ShuffleBetweenShards: shuffleBetweenShards,
MaxNodesEnableConfig: nil,
EnableEpochsHandler: &testscommon.EnableEpochsHandlerStub{},
}
nodeShuffler, _ := nodesCoordinator.NewHashValidatorsShuffler(nodeShufflerArgs)
argumentsNodesCoordinator := nodesCoordinator.ArgNodesCoordinator{
ShardConsensusGroupSize: arg.shardConsensusGroupSize,
MetaConsensusGroupSize: arg.metaConsensusGroupSize,
Marshalizer: TestMarshalizer,
Hasher: arg.hasher,
Shuffler: nodeShuffler,
EpochStartNotifier: arg.epochStartSubscriber,
ShardIDAsObserver: arg.shardId,
NbShards: uint32(arg.nbShards),
EligibleNodes: arg.validatorsMap,
WaitingNodes: arg.waitingMap,
SelfPublicKey: pubKeyBytes,
ConsensusGroupCache: arg.consensusGroupCache,
BootStorer: arg.bootStorer,
ShuffledOutHandler: &mock.ShuffledOutHandlerStub{},
ChanStopNode: endProcess.GetDummyEndProcessChannel(),
NodeTypeProvider: &nodeTypeProviderMock.NodeTypeProviderStub{},
IsFullArchive: false,
EnableEpochsHandler: &testscommon.EnableEpochsHandlerStub{
RefactorPeersMiniBlocksEnableEpochField: UnreachableEpoch,
},
ValidatorInfoCacher: &vic.ValidatorInfoCacherStub{},
}
nodesCoord, err := nodesCoordinator.NewIndexHashedNodesCoordinator(argumentsNodesCoordinator)
if err != nil {
fmt.Println("Error creating node coordinator")
}
return nodesCoord
}
// IndexHashedNodesCoordinatorWithRaterFactory -
type IndexHashedNodesCoordinatorWithRaterFactory struct {
sharding.PeerAccountListAndRatingHandler
}
// CreateNodesCoordinator is used for creating a nodes coordinator in the integration tests
// based on the provided parameters
func (ihncrf *IndexHashedNodesCoordinatorWithRaterFactory) CreateNodesCoordinator(
arg ArgIndexHashedNodesCoordinatorFactory,
) nodesCoordinator.NodesCoordinator {
keys := arg.cp.Keys[arg.shardId][arg.keyIndex]
pubKeyBytes, _ := keys.Pk.ToByteArray()
shufflerArgs := &nodesCoordinator.NodesShufflerArgs{
NodesShard: uint32(arg.nodesPerShard),
NodesMeta: uint32(arg.nbMetaNodes),
Hysteresis: hysteresis,
Adaptivity: adaptivity,
ShuffleBetweenShards: shuffleBetweenShards,
MaxNodesEnableConfig: nil,
EnableEpochsHandler: &testscommon.EnableEpochsHandlerStub{
IsWaitingListFixFlagEnabledField: true,
IsBalanceWaitingListsFlagEnabledField: true,
},
}
nodeShuffler, _ := nodesCoordinator.NewHashValidatorsShuffler(shufflerArgs)
argumentsNodesCoordinator := nodesCoordinator.ArgNodesCoordinator{
ShardConsensusGroupSize: arg.shardConsensusGroupSize,
MetaConsensusGroupSize: arg.metaConsensusGroupSize,
Marshalizer: TestMarshalizer,
Hasher: arg.hasher,
Shuffler: nodeShuffler,
EpochStartNotifier: arg.epochStartSubscriber,
ShardIDAsObserver: arg.shardId,
NbShards: uint32(arg.nbShards),
EligibleNodes: arg.validatorsMap,
WaitingNodes: arg.waitingMap,
SelfPublicKey: pubKeyBytes,
ConsensusGroupCache: arg.consensusGroupCache,
BootStorer: arg.bootStorer,
ShuffledOutHandler: &mock.ShuffledOutHandlerStub{},
ChanStopNode: endProcess.GetDummyEndProcessChannel(),
NodeTypeProvider: &nodeTypeProviderMock.NodeTypeProviderStub{},
IsFullArchive: false,
EnableEpochsHandler: &testscommon.EnableEpochsHandlerStub{
IsWaitingListFixFlagEnabledField: true,
RefactorPeersMiniBlocksEnableEpochField: UnreachableEpoch,
},
ValidatorInfoCacher: &vic.ValidatorInfoCacherStub{},
}
baseCoordinator, err := nodesCoordinator.NewIndexHashedNodesCoordinator(argumentsNodesCoordinator)
if err != nil {
log.Debug("Error creating node coordinator")
}
nodesCoord, err := nodesCoordinator.NewIndexHashedNodesCoordinatorWithRater(baseCoordinator, ihncrf.PeerAccountListAndRatingHandler)
if err != nil {
log.Debug("Error creating node coordinator")
}
return &NodesWithRater{
NodesCoordinator: nodesCoord,
rater: ihncrf.PeerAccountListAndRatingHandler,
}
}
// NodesWithRater -
type NodesWithRater struct {
nodesCoordinator.NodesCoordinator
rater sharding.PeerAccountListAndRatingHandler
}
// IsInterfaceNil -
func (nwr *NodesWithRater) IsInterfaceNil() bool {
return nwr == nil
}