Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into fix-import-db-resource-leak
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau authored Jan 16, 2024
2 parents a77df11 + 229ae2e commit ea525d8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 8 deletions.
13 changes: 6 additions & 7 deletions consensus/spos/bls/subroundStartRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,14 @@ func (sr *subroundStartRound) initCurrentRound() bool {

sr.indexRoundIfNeeded(pubKeys)

_, err = sr.SelfConsensusGroupIndex()
if err != nil {
if numMultiKeysInConsensusGroup == 0 {
log.Debug("not in consensus group")
}
isSingleKeyLeader := leader == sr.SelfPubKey() && sr.ShouldConsiderSelfKeyInConsensus()
isLeader := isSingleKeyLeader || sr.IsKeyManagedByCurrentNode([]byte(leader))
isSelfInConsensus := sr.IsNodeInConsensusGroup(sr.SelfPubKey()) || numMultiKeysInConsensusGroup > 0
if !isSelfInConsensus {
log.Debug("not in consensus group")
sr.AppStatusHandler().SetStringValue(common.MetricConsensusState, "not in consensus group")
} else {
isLeader := leader == sr.SelfPubKey() && sr.ShouldConsiderSelfKeyInConsensus()
if !isLeader && !sr.IsKeyManagedByCurrentNode([]byte(leader)) {
if !isLeader {
sr.AppStatusHandler().Increment(common.MetricCountConsensus)
sr.AppStatusHandler().SetStringValue(common.MetricConsensusState, "participant")
}
Expand Down
68 changes: 67 additions & 1 deletion consensus/spos/bls/subroundStartRound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,66 @@ func TestSubroundStartRound_InitCurrentRoundShouldMetrics(t *testing.T) {
srStartRound.Check()
assert.True(t, wasCalled)
})
t.Run("participant node", func(t *testing.T) {
t.Run("main key participant", func(t *testing.T) {
t.Parallel()

wasCalled := false
wasIncrementCalled := false
container := mock.InitConsensusCore()
keysHandler := &testscommon.KeysHandlerStub{
IsKeyManagedByCurrentNodeCalled: func(pkBytes []byte) bool {
return string(pkBytes) == "B"
},
}
appStatusHandler := &statusHandler.AppStatusHandlerStub{
SetStringValueHandler: func(key string, value string) {
if key == common.MetricConsensusState {
wasCalled = true
assert.Equal(t, "participant", value)
}
},
IncrementHandler: func(key string) {
if key == common.MetricCountConsensus {
wasIncrementCalled = true
}
},
}
ch := make(chan bool, 1)
consensusState := initConsensusStateWithKeysHandler(keysHandler)
consensusState.SetSelfPubKey("B")
sr, _ := spos.NewSubround(
-1,
bls.SrStartRound,
bls.SrBlock,
int64(85*roundTimeDuration/100),
int64(95*roundTimeDuration/100),
"(START_ROUND)",
consensusState,
ch,
executeStoredMessages,
container,
chainID,
currentPid,
appStatusHandler,
)

srStartRound, _ := bls.NewSubroundStartRound(
sr,
extend,
bls.ProcessingThresholdPercent,
displayStatistics,
executeStoredMessages,
&mock.SentSignatureTrackerStub{},
)
srStartRound.Check()
assert.True(t, wasCalled)
assert.True(t, wasIncrementCalled)
})
t.Run("multi key participant", func(t *testing.T) {
t.Parallel()

wasCalled := false
wasIncrementCalled := false
container := mock.InitConsensusCore()
keysHandler := &testscommon.KeysHandlerStub{}
appStatusHandler := &statusHandler.AppStatusHandlerStub{
Expand All @@ -579,9 +635,17 @@ func TestSubroundStartRound_InitCurrentRoundShouldMetrics(t *testing.T) {
assert.Equal(t, value, "participant")
}
},
IncrementHandler: func(key string) {
if key == common.MetricCountConsensus {
wasIncrementCalled = true
}
},
}
ch := make(chan bool, 1)
consensusState := initConsensusStateWithKeysHandler(keysHandler)
keysHandler.IsKeyManagedByCurrentNodeCalled = func(pkBytes []byte) bool {
return string(pkBytes) == consensusState.SelfPubKey()
}
sr, _ := spos.NewSubround(
-1,
bls.SrStartRound,
Expand All @@ -608,6 +672,7 @@ func TestSubroundStartRound_InitCurrentRoundShouldMetrics(t *testing.T) {
)
srStartRound.Check()
assert.True(t, wasCalled)
assert.True(t, wasIncrementCalled)
})
t.Run("main key leader", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -709,6 +774,7 @@ func TestSubroundStartRound_InitCurrentRoundShouldMetrics(t *testing.T) {
ch := make(chan bool, 1)
consensusState := initConsensusStateWithKeysHandler(keysHandler)
leader, _ := consensusState.GetLeader()
consensusState.SetSelfPubKey(leader)
keysHandler.IsKeyManagedByCurrentNodeCalled = func(pkBytes []byte) bool {
return string(pkBytes) == leader
}
Expand Down

0 comments on commit ea525d8

Please sign in to comment.