Skip to content

Commit

Permalink
Merge pull request #5840 from multiversx/fix-wrong-backup-step-in
Browse files Browse the repository at this point in the history
Fixed wrong multikey backup machine step-in
  • Loading branch information
iulianpascalau authored Jan 23, 2024
2 parents c84a6e6 + 7cab217 commit 4cea6b5
Show file tree
Hide file tree
Showing 46 changed files with 416 additions and 142 deletions.
2 changes: 1 addition & 1 deletion consensus/spos/bls/blsSubroundsFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func checkNewFactoryParams(
return spos.ErrNilAppStatusHandler
}
if check.IfNil(sentSignaturesTracker) {
return spos.ErrNilSentSignatureTracker
return ErrNilSentSignatureTracker
}
if len(chainID) == 0 {
return spos.ErrInvalidChainID
Expand Down
37 changes: 19 additions & 18 deletions consensus/spos/bls/blsSubroundsFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/consensus/spos/bls"
"github.com/multiversx/mx-chain-go/outport"
"github.com/multiversx/mx-chain-go/testscommon"
testscommonOutport "github.com/multiversx/mx-chain-go/testscommon/outport"
"github.com/multiversx/mx-chain-go/testscommon/statusHandler"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -76,7 +77,7 @@ func initFactoryWithContainer(container *mock.ConsensusCoreMock) bls.Factory {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

return fct
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestFactory_NewFactoryNilContainerShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -145,7 +146,7 @@ func TestFactory_NewFactoryNilConsensusStateShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -167,7 +168,7 @@ func TestFactory_NewFactoryNilBlockchainShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -189,7 +190,7 @@ func TestFactory_NewFactoryNilBlockProcessorShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -211,7 +212,7 @@ func TestFactory_NewFactoryNilBootstrapperShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -233,7 +234,7 @@ func TestFactory_NewFactoryNilChronologyHandlerShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -255,7 +256,7 @@ func TestFactory_NewFactoryNilHasherShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -277,7 +278,7 @@ func TestFactory_NewFactoryNilMarshalizerShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -299,7 +300,7 @@ func TestFactory_NewFactoryNilMultiSignerContainerShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -321,7 +322,7 @@ func TestFactory_NewFactoryNilRoundHandlerShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -343,7 +344,7 @@ func TestFactory_NewFactoryNilShardCoordinatorShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -365,7 +366,7 @@ func TestFactory_NewFactoryNilSyncTimerShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -387,7 +388,7 @@ func TestFactory_NewFactoryNilValidatorGroupSelectorShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -407,7 +408,7 @@ func TestFactory_NewFactoryNilWorkerShouldFail(t *testing.T) {
chainID,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -428,7 +429,7 @@ func TestFactory_NewFactoryNilAppStatusHandlerShouldFail(t *testing.T) {
chainID,
currentPid,
nil,
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand All @@ -453,7 +454,7 @@ func TestFactory_NewFactoryNilSignaturesTrackerShouldFail(t *testing.T) {
)

assert.Nil(t, fct)
assert.Equal(t, spos.ErrNilSentSignatureTracker, err)
assert.Equal(t, bls.ErrNilSentSignatureTracker, err)
}

func TestFactory_NewFactoryShouldWork(t *testing.T) {
Expand All @@ -478,7 +479,7 @@ func TestFactory_NewFactoryEmptyChainIDShouldFail(t *testing.T) {
nil,
currentPid,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, fct)
Expand Down
6 changes: 6 additions & 0 deletions consensus/spos/bls/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package bls

import "errors"

// ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker
var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker")
5 changes: 1 addition & 4 deletions consensus/spos/bls/subroundEndRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewSubroundEndRound(
return nil, spos.ErrNilAppStatusHandler
}
if check.IfNil(sentSignatureTracker) {
return nil, spos.ErrNilSentSignatureTracker
return nil, ErrNilSentSignatureTracker
}

srEndRound := subroundEndRound{
Expand Down Expand Up @@ -120,9 +120,6 @@ func (sr *subroundEndRound) receivedBlockHeaderFinalInfo(_ context.Context, cnsD
"AggregateSignature", cnsDta.AggregateSignature,
"LeaderSignature", cnsDta.LeaderSignature)

signers := computeSignersPublicKeys(sr.ConsensusGroup(), cnsDta.PubKeysBitmap)
sr.sentSignatureTracker.ReceivedActualSigners(signers)

sr.PeerHonestyHandler().ChangeScore(
node,
spos.GetConsensusTopicID(sr.ShardCoordinator()),
Expand Down
36 changes: 14 additions & 22 deletions consensus/spos/bls/subroundEndRound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func initSubroundEndRoundWithContainer(
bls.ProcessingThresholdPercent,
displayStatistics,
appStatusHandler,
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

return srEndRound
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestNewSubroundEndRound(t *testing.T) {
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, srEndRound)
Expand All @@ -112,7 +112,7 @@ func TestNewSubroundEndRound(t *testing.T) {
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, srEndRound)
Expand All @@ -127,7 +127,7 @@ func TestNewSubroundEndRound(t *testing.T) {
bls.ProcessingThresholdPercent,
displayStatistics,
nil,
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.Nil(t, srEndRound)
Expand All @@ -146,7 +146,7 @@ func TestNewSubroundEndRound(t *testing.T) {
)

assert.Nil(t, srEndRound)
assert.Equal(t, spos.ErrNilSentSignatureTracker, err)
assert.Equal(t, bls.ErrNilSentSignatureTracker, err)
})
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func TestSubroundEndRound_NewSubroundEndRoundNilBlockChainShouldFail(t *testing.
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.True(t, check.IfNil(srEndRound))
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestSubroundEndRound_NewSubroundEndRoundNilBlockProcessorShouldFail(t *test
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.True(t, check.IfNil(srEndRound))
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestSubroundEndRound_NewSubroundEndRoundNilConsensusStateShouldFail(t *test
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.True(t, check.IfNil(srEndRound))
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestSubroundEndRound_NewSubroundEndRoundNilMultiSignerContainerShouldFail(t
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.True(t, check.IfNil(srEndRound))
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestSubroundEndRound_NewSubroundEndRoundNilRoundHandlerShouldFail(t *testin
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.True(t, check.IfNil(srEndRound))
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestSubroundEndRound_NewSubroundEndRoundNilSyncTimerShouldFail(t *testing.T
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.True(t, check.IfNil(srEndRound))
Expand Down Expand Up @@ -396,7 +396,7 @@ func TestSubroundEndRound_NewSubroundEndRoundShouldWork(t *testing.T) {
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

assert.False(t, check.IfNil(srEndRound))
Expand Down Expand Up @@ -902,16 +902,8 @@ func TestSubroundEndRound_ReceivedBlockHeaderFinalInfoShouldWork(t *testing.T) {
PubKey: []byte("A"),
}

sentTrackerInterface := sr.GetSentSignatureTracker()
sentTracker := sentTrackerInterface.(*mock.SentSignatureTrackerStub)
receivedActualSignersCalled := false
sentTracker.ReceivedActualSignersCalled = func(signersPks []string) {
receivedActualSignersCalled = true
}

res := sr.ReceivedBlockHeaderFinalInfo(&cnsData)
assert.True(t, res)
assert.True(t, receivedActualSignersCalled)
}

func TestSubroundEndRound_ReceivedBlockHeaderFinalInfoShouldReturnFalseWhenFinalInfoIsNotValid(t *testing.T) {
Expand Down Expand Up @@ -1372,7 +1364,7 @@ func TestSubroundEndRound_ReceivedInvalidSignersInfo(t *testing.T) {
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

srEndRound.SetSelfPubKey("A")
Expand Down Expand Up @@ -1743,7 +1735,7 @@ func TestSubroundEndRound_getMinConsensusGroupIndexOfManagedKeys(t *testing.T) {
bls.ProcessingThresholdPercent,
displayStatistics,
&statusHandler.AppStatusHandlerStub{},
&mock.SentSignatureTrackerStub{},
&testscommon.SentSignatureTrackerStub{},
)

t.Run("no managed keys from consensus group", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/spos/bls/subroundSignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewSubroundSignature(
return nil, spos.ErrNilAppStatusHandler
}
if check.IfNil(sentSignatureTracker) {
return nil, spos.ErrNilSentSignatureTracker
return nil, ErrNilSentSignatureTracker
}

srSignature := subroundSignature{
Expand Down
Loading

0 comments on commit 4cea6b5

Please sign in to comment.