Skip to content

Commit ab80e79

Browse files
authored
remove active node registry when participation score reach 0 (#1328)
* remove active node registry when participation score reach 0 * calculateNodeOrder divide by 1, it is not used anymore, will be removed in new blocksmith selection implementation #1190 * omit division * fix tests * remove outdated test
1 parent c9bb2f8 commit ab80e79

File tree

4 files changed

+3
-172
lines changed

4 files changed

+3
-172
lines changed

core/smith/strategy/blocksmithStrategyMain_test.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -174,83 +174,6 @@ func (*mockActiveNodeRegistryCacheSuccessWithContent) GetAllItems(item interface
174174
return nil
175175
}
176176

177-
func TestBlocksmithService_GetBlocksmiths(t *testing.T) {
178-
type fields struct {
179-
QueryExecutor query.ExecutorInterface
180-
NodeRegistrationQuery query.NodeRegistrationQueryInterface
181-
Logger *log.Logger
182-
SortedBlocksmiths []*model.Blocksmith
183-
SortedBlocksmithsMap map[string]*int64
184-
SortedBlocksmithsMapLock sync.RWMutex
185-
ActiveNodeRegistryCache storage.CacheStorageInterface
186-
}
187-
type args struct {
188-
block *model.Block
189-
}
190-
tests := []struct {
191-
name string
192-
fields fields
193-
args args
194-
want []*model.Blocksmith
195-
wantErr bool
196-
}{
197-
{
198-
name: "success - no blocksmiths",
199-
fields: fields{
200-
QueryExecutor: &mockQueryGetBlocksmithsMainSuccessNoBlocksmith{},
201-
NodeRegistrationQuery: query.NewNodeRegistrationQuery(),
202-
ActiveNodeRegistryCache: &mockActiveNodeRegistryCacheSuccess{},
203-
204-
Logger: log.New(),
205-
},
206-
args: args{&model.Block{}},
207-
wantErr: false,
208-
want: nil,
209-
},
210-
{
211-
name: "success - with blocksmiths",
212-
fields: fields{
213-
QueryExecutor: &mockQueryGetBlocksmithsMainSuccessWithBlocksmith{},
214-
NodeRegistrationQuery: query.NewNodeRegistrationQuery(),
215-
Logger: log.New(),
216-
ActiveNodeRegistryCache: &mockActiveNodeRegistryCacheSuccessWithContent{},
217-
},
218-
args: args{mockBlock},
219-
wantErr: false,
220-
want: []*model.Blocksmith{
221-
{
222-
NodeID: bssMockBlocksmiths[0].NodeID,
223-
BlockSeed: -7765827254621503546,
224-
NodeOrder: new(big.Int).SetInt64(13195850646937615),
225-
Score: bssMockBlocksmiths[0].Score,
226-
NodePublicKey: bssMockBlocksmiths[0].NodePublicKey,
227-
},
228-
},
229-
},
230-
}
231-
for _, tt := range tests {
232-
t.Run(tt.name, func(t *testing.T) {
233-
bss := &BlocksmithStrategyMain{
234-
QueryExecutor: tt.fields.QueryExecutor,
235-
NodeRegistrationQuery: tt.fields.NodeRegistrationQuery,
236-
Logger: tt.fields.Logger,
237-
ActiveNodeRegistryCache: tt.fields.ActiveNodeRegistryCache,
238-
SortedBlocksmiths: tt.fields.SortedBlocksmiths,
239-
SortedBlocksmithsMap: tt.fields.SortedBlocksmithsMap,
240-
SortedBlocksmithsLock: tt.fields.SortedBlocksmithsMapLock,
241-
}
242-
got, err := bss.GetBlocksmiths(tt.args.block)
243-
if (err != nil) != tt.wantErr {
244-
t.Errorf("GetBlocksmiths() error = %v, wantErr %v", err, tt.wantErr)
245-
return
246-
}
247-
if !reflect.DeepEqual(got, tt.want) {
248-
t.Errorf("GetBlocksmiths() got = %v, want %v", got, tt.want)
249-
}
250-
})
251-
}
252-
}
253-
254177
func TestBlocksmithService_GetSortedBlocksmiths(t *testing.T) {
255178
type fields struct {
256179
QueryExecutor query.ExecutorInterface

core/smith/strategy/blocksmithStrategySpine_test.go

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -219,98 +219,6 @@ func (*mockQueryGetBlocksmithsSpineSuccessNoBlocksmith) ExecuteSelectRow(qStr st
219219
return db.QueryRow(qStr), nil
220220
}
221221

222-
func TestBlocksmithStrategySpine_GetBlocksmiths(t *testing.T) {
223-
type fields struct {
224-
QueryExecutor query.ExecutorInterface
225-
SpinePublicKeyQuery query.SpinePublicKeyQueryInterface
226-
Logger *log.Logger
227-
SortedBlocksmiths []*model.Blocksmith
228-
LastSortedBlockID int64
229-
SortedBlocksmithsMap map[string]*int64
230-
}
231-
type args struct {
232-
block *model.Block
233-
}
234-
tests := []struct {
235-
name string
236-
fields fields
237-
args args
238-
want []*model.Blocksmith
239-
wantErr bool
240-
}{
241-
{
242-
name: "GetBlocksmiths:success",
243-
fields: fields{
244-
QueryExecutor: &mockQueryGetBlocksmithsSpineSuccessWithBlocksmith{},
245-
SpinePublicKeyQuery: query.NewSpinePublicKeyQuery(),
246-
Logger: log.New(),
247-
SortedBlocksmiths: nil,
248-
SortedBlocksmithsMap: make(map[string]*int64),
249-
LastSortedBlockID: 1,
250-
},
251-
args: args{mockBlock},
252-
wantErr: false,
253-
want: []*model.Blocksmith{
254-
{
255-
NodeID: bssMockBlocksmiths[0].NodeID,
256-
BlockSeed: -1965565459747201754,
257-
NodeOrder: new(big.Int).SetInt64(28),
258-
Score: big.NewInt(constant.DefaultParticipationScore),
259-
NodePublicKey: bssMockBlocksmiths[0].NodePublicKey,
260-
},
261-
},
262-
},
263-
{
264-
name: "GetBlocksmiths:fail-{sqlSelectErr}",
265-
fields: fields{
266-
QueryExecutor: &mockQueryGetBlocksmithsSpineFail{},
267-
SpinePublicKeyQuery: query.NewSpinePublicKeyQuery(),
268-
Logger: log.New(),
269-
SortedBlocksmiths: nil,
270-
SortedBlocksmithsMap: make(map[string]*int64),
271-
LastSortedBlockID: 1,
272-
},
273-
args: args{mockBlock},
274-
wantErr: true,
275-
want: nil,
276-
},
277-
{
278-
name: "GetBlocksmiths:fail-{noSpinePublicKeyFound}",
279-
fields: fields{
280-
QueryExecutor: &mockQueryGetBlocksmithsSpineSuccessNoBlocksmith{},
281-
SpinePublicKeyQuery: query.NewSpinePublicKeyQuery(),
282-
Logger: log.New(),
283-
SortedBlocksmiths: nil,
284-
SortedBlocksmithsMap: make(map[string]*int64),
285-
LastSortedBlockID: 1,
286-
},
287-
args: args{mockBlock},
288-
wantErr: false,
289-
want: nil,
290-
},
291-
}
292-
for _, tt := range tests {
293-
t.Run(tt.name, func(t *testing.T) {
294-
bss := &BlocksmithStrategySpine{
295-
QueryExecutor: tt.fields.QueryExecutor,
296-
SpinePublicKeyQuery: tt.fields.SpinePublicKeyQuery,
297-
Logger: tt.fields.Logger,
298-
SortedBlocksmiths: tt.fields.SortedBlocksmiths,
299-
LastSortedBlockID: tt.fields.LastSortedBlockID,
300-
SortedBlocksmithsMap: tt.fields.SortedBlocksmithsMap,
301-
}
302-
got, err := bss.GetBlocksmiths(tt.args.block)
303-
if (err != nil) != tt.wantErr {
304-
t.Errorf("BlocksmithStrategySpine.GetBlocksmiths() error = %v, wantErr %v", err, tt.wantErr)
305-
return
306-
}
307-
if !reflect.DeepEqual(got, tt.want) {
308-
t.Errorf("BlocksmithStrategySpine.GetBlocksmiths() = %v, want %v", got, tt.want)
309-
}
310-
})
311-
}
312-
}
313-
314222
func TestBlocksmithStrategySpine_SortBlocksmiths(t *testing.T) {
315223
type fields struct {
316224
QueryExecutor query.ExecutorInterface

core/util/blockUtil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func IsBlockIDExist(blockIds []int64, expectedBlockID int64) bool {
8787
// CalculateNodeOrder calculate the Node order parameter, used to sort/select the group of blocksmith rewarded for a given block
8888
func CalculateNodeOrder(score *big.Int, blockSeed, nodeID int64) *big.Int {
8989
prn := crypto.PseudoRandomGenerator(uint64(nodeID), uint64(blockSeed), crypto.PseudoRandomSha3256)
90-
return new(big.Int).Div(new(big.Int).SetUint64(prn), score)
90+
return new(big.Int).SetUint64(prn)
9191
}
9292

9393
func IsGenesis(previousBlockID int64, block *model.Block) bool {

core/util/blockUtil_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func TestCalculateNodeOrder(t *testing.T) {
236236
blockSeed: 1000,
237237
nodeID: int64(1000),
238238
},
239-
want: "7357219233906154",
239+
want: "7357219233906154824",
240240
},
241241
{
242242
name: "CalculateNodeOrder:success2",
@@ -245,7 +245,7 @@ func TestCalculateNodeOrder(t *testing.T) {
245245
blockSeed: 3000,
246246
nodeID: int64(10),
247247
},
248-
want: "2461325401382821",
248+
want: "4922650802765643438",
249249
},
250250
}
251251
for _, tt := range tests {

0 commit comments

Comments
 (0)