Skip to content

Commit 210f52b

Browse files
authored
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
2 parents 21fd3ea + b940950 commit 210f52b

File tree

4 files changed

+94
-8
lines changed

4 files changed

+94
-8
lines changed

consensus/spos/bls/v2/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ import "errors"
44

55
// ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker
66
var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker")
7+
8+
// ErrTimeOut signals that the time is out
9+
var ErrTimeOut = errors.New("time is out")

consensus/spos/bls/v2/export_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,6 @@ func (sr *subroundEndRound) GetEquivalentProofSender() string {
362362
}
363363

364364
// SendProof -
365-
func (sr *subroundEndRound) SendProof() {
366-
_, _ = sr.sendProof()
365+
func (sr *subroundEndRound) SendProof() (bool, error) {
366+
return sr.sendProof()
367367
}

consensus/spos/bls/v2/subroundEndRound.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (sr *subroundEndRound) sendProof() (bool, error) {
367367
log.Debug("sendProof: time is out -> cancel broadcasting final info and header",
368368
"round time stamp", roundHandler.TimeStamp(),
369369
"current time", time.Now())
370-
return false, err
370+
return false, ErrTimeOut
371371
}
372372

373373
// broadcast header proof

consensus/spos/bls/v2/subroundEndRound_test.go

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,9 @@ func TestSubroundEndRound_SendProof(t *testing.T) {
22902290
},
22912291
}
22922292
container.SetBroadcastMessenger(bm)
2293-
sr.SendProof()
2293+
wasSent, err := sr.SendProof()
2294+
require.False(t, wasSent)
2295+
require.NoError(t, err)
22942296
})
22952297
t.Run("not enough signatures should not send proof", func(t *testing.T) {
22962298
t.Parallel()
@@ -2305,18 +2307,97 @@ func TestSubroundEndRound_SendProof(t *testing.T) {
23052307
},
23062308
}
23072309
container.SetBroadcastMessenger(bm)
2308-
sr.SendProof()
2310+
wasSent, err := sr.SendProof()
2311+
require.False(t, wasSent)
2312+
require.Error(t, err)
2313+
})
2314+
t.Run("signature aggregation failure should not send proof", func(t *testing.T) {
2315+
t.Parallel()
2316+
2317+
container := consensusMocks.InitConsensusCore()
2318+
sr := initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{})
2319+
2320+
bm := &consensusMocks.BroadcastMessengerMock{
2321+
BroadcastEquivalentProofCalled: func(proof data.HeaderProofHandler, pkBytes []byte) error {
2322+
require.Fail(t, "should have not been called")
2323+
return nil
2324+
},
2325+
}
2326+
container.SetBroadcastMessenger(bm)
2327+
signingHandler := &consensusMocks.SigningHandlerStub{
2328+
AggregateSigsCalled: func(bitmap []byte, epoch uint32) ([]byte, error) {
2329+
return nil, expectedErr
2330+
},
2331+
}
2332+
container.SetSigningHandler(signingHandler)
2333+
2334+
for _, pubKey := range sr.ConsensusGroup() {
2335+
_ = sr.SetJobDone(pubKey, bls.SrSignature, true)
2336+
}
2337+
2338+
wasSent, err := sr.SendProof()
2339+
require.False(t, wasSent)
2340+
require.Equal(t, expectedErr, err)
2341+
})
2342+
t.Run("no time left should not send proof", func(t *testing.T) {
2343+
t.Parallel()
2344+
2345+
container := consensusMocks.InitConsensusCore()
2346+
sr := initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{})
2347+
2348+
bm := &consensusMocks.BroadcastMessengerMock{
2349+
BroadcastEquivalentProofCalled: func(proof data.HeaderProofHandler, pkBytes []byte) error {
2350+
require.Fail(t, "should have not been called")
2351+
return nil
2352+
},
2353+
}
2354+
container.SetBroadcastMessenger(bm)
2355+
roundHandler := &consensusMocks.RoundHandlerMock{
2356+
RemainingTimeCalled: func(startTime time.Time, maxTime time.Duration) time.Duration {
2357+
return -1 // no time left
2358+
},
2359+
}
2360+
container.SetRoundHandler(roundHandler)
2361+
2362+
for _, pubKey := range sr.ConsensusGroup() {
2363+
_ = sr.SetJobDone(pubKey, bls.SrSignature, true)
2364+
}
2365+
2366+
wasSent, err := sr.SendProof()
2367+
require.False(t, wasSent)
2368+
require.Equal(t, v2.ErrTimeOut, err)
2369+
})
2370+
t.Run("broadcast failure should not send proof", func(t *testing.T) {
2371+
t.Parallel()
2372+
2373+
container := consensusMocks.InitConsensusCore()
2374+
sr := initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{})
2375+
2376+
bm := &consensusMocks.BroadcastMessengerMock{
2377+
BroadcastEquivalentProofCalled: func(proof data.HeaderProofHandler, pkBytes []byte) error {
2378+
return expectedErr
2379+
},
2380+
}
2381+
container.SetBroadcastMessenger(bm)
2382+
2383+
for _, pubKey := range sr.ConsensusGroup() {
2384+
_ = sr.SetJobDone(pubKey, bls.SrSignature, true)
2385+
}
2386+
2387+
wasSent, err := sr.SendProof()
2388+
require.False(t, wasSent)
2389+
require.Equal(t, expectedErr, err)
23092390
})
23102391
t.Run("should send", func(t *testing.T) {
23112392
t.Parallel()
23122393

23132394
container := consensusMocks.InitConsensusCore()
23142395
sr := initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{})
23152396

2316-
wasSent := false
2397+
wasBroadcastEquivalentProofCalled := false
23172398
bm := &consensusMocks.BroadcastMessengerMock{
23182399
BroadcastEquivalentProofCalled: func(proof data.HeaderProofHandler, pkBytes []byte) error {
2319-
wasSent = true
2400+
wasBroadcastEquivalentProofCalled = true
23202401
return nil
23212402
},
23222403
}
@@ -2326,7 +2407,9 @@ func TestSubroundEndRound_SendProof(t *testing.T) {
23262407
_ = sr.SetJobDone(pubKey, bls.SrSignature, true)
23272408
}
23282409

2329-
sr.SendProof()
2410+
wasSent, err := sr.SendProof()
23302411
require.True(t, wasSent)
2412+
require.NoError(t, err)
2413+
require.True(t, wasBroadcastEquivalentProofCalled)
23312414
})
23322415
}

0 commit comments

Comments
 (0)