Skip to content

Commit

Permalink
Merge branch 'release/0.4.0' into fix/incomplete-process-marshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
loongy committed Aug 10, 2020
2 parents bfb1e8b + 9e366af commit 6bb2a0e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (p *Process) tryPrevoteUponSufficientPrevotes() {
if !ok {
return
}
if propose.ValidRound == InvalidRound || propose.ValidRound >= p.CurrentRound {
if propose.ValidRound <= InvalidRound || propose.ValidRound >= p.CurrentRound {
return
}

Expand Down Expand Up @@ -705,6 +705,10 @@ func (p *Process) insertPropose(propose Propose) bool {
return false
}

if propose.Round <= InvalidRound {
return false
}

if p.scheduler != nil {
proposer := p.scheduler.Schedule(propose.Height, propose.Round)
if !proposer.Equal(&propose.From) {
Expand Down
34 changes: 34 additions & 0 deletions process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,40 @@ var _ = Describe("Process", func() {
Expect(quick.Check(f, nil)).To(Succeed())
})
})

Context("when the propose is for an invalid round", func() {
It("should not panic", func() {
loop := func() bool {
currentHeight := process.Height(r.Int63())
currentRound := process.Round(r.Int63())
whoami := id.NewPrivKey().Signatory()
f := 5 + (r.Int() % 10)

// instantiate a new process
scheduledProposer := id.NewPrivKey().Signatory()
scheduler := scheduler.NewRoundRobin([]id.Signatory{scheduledProposer})
p := process.New(whoami, f, nil, scheduler, nil, nil, nil, nil, nil)
p.StartRound(currentRound)

// update the state
p.State.CurrentHeight = currentHeight
p.State.CurrentStep = process.Proposing
p.State.LockedRound = process.InvalidRound

// insert a propose for an invalid round
propose := processutil.RandomPropose(r)
propose.From = scheduledProposer
propose.Height = currentHeight
propose.Round = process.Round(-r.Int63())
Expect(func() {
p.Propose(propose)
}).ToNot(Panic())

return true
}
Expect(quick.Check(loop, nil)).To(Succeed())
})
})
})

Context("when we are not in the propose step", func() {
Expand Down

0 comments on commit 6bb2a0e

Please sign in to comment.