Skip to content

Commit

Permalink
Merge pull request #35 from renproject/fix/nil-prevote-threshold
Browse files Browse the repository at this point in the history
Update DidReceiveSufficientNilPrevotes interface and reduce threshold
  • Loading branch information
loongy authored Oct 23, 2019
2 parents 278b7e1 + 8a3b9fa commit 32a55d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
29 changes: 15 additions & 14 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Validator interface {
// An Observer is notified when note-worthy events happen for the first time.
type Observer interface {
DidCommitBlock(block.Height)
DidReceiveSufficientNilPrevotes(messages Messages, threshold int)
DidReceiveSufficientNilPrevotes(messages Messages, f int)
}

// A Scheduler determines which `id.Signatory` should be broadcasting
Expand Down Expand Up @@ -318,20 +318,21 @@ func (p *Process) handlePrevote(prevote *Prevote) {
p.scheduleTimeoutPrevote(p.state.CurrentHeight, p.state.CurrentRound, p.timer.Timeout(StepPrevote, p.state.CurrentRound))
}

// upon 2f+1 Prevote{currentHeight, currentRound, nil} while currentStep = StepPrevote
if n := p.state.Prevotes.QueryByHeightRoundBlockHash(p.state.CurrentHeight, p.state.CurrentRound, block.InvalidHash); n > 2*p.state.Prevotes.F() {
if p.state.CurrentStep == StepPrevote {
precommit := NewPrecommit(
p.state.CurrentHeight,
p.state.CurrentRound,
block.InvalidHash,
)
p.logger.Debugf("precommited=<nil> at height=%v and round=%v (2f+1 prevote=<nil>)", precommit.height, precommit.round)
p.state.CurrentStep = StepPrecommit
p.broadcaster.Broadcast(precommit)
}
// upon f+1 Prevote{currentHeight, currentRound, nil}
if n := p.state.Prevotes.QueryByHeightRoundBlockHash(p.state.CurrentHeight, p.state.CurrentRound, block.InvalidHash); n > p.state.Prevotes.F() {
p.observer.DidReceiveSufficientNilPrevotes(p.state.Prevotes.QueryMessagesByHeightRound(p.state.CurrentHeight, p.state.CurrentRound), p.state.Prevotes.F())
}

p.observer.DidReceiveSufficientNilPrevotes(p.state.Prevotes.QueryMessagesByHeightRound(p.state.CurrentHeight, p.state.CurrentRound), 2*p.state.Prevotes.F()+1)
// upon 2f+1 Prevote{currentHeight, currentRound, nil} while currentStep = StepPrevote
if n := p.state.Prevotes.QueryByHeightRoundBlockHash(p.state.CurrentHeight, p.state.CurrentRound, block.InvalidHash); n > 2*p.state.Prevotes.F() && p.state.CurrentStep == StepPrevote {
precommit := NewPrecommit(
p.state.CurrentHeight,
p.state.CurrentRound,
block.InvalidHash,
)
p.logger.Debugf("precommited=<nil> at height=%v and round=%v (2f+1 prevote=<nil>)", precommit.height, precommit.round)
p.state.CurrentStep = StepPrecommit
p.broadcaster.Broadcast(precommit)
}

// upon f+1 *{currentHeight, round, *, *} and round > currentRound
Expand Down
6 changes: 3 additions & 3 deletions replica/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Validator interface {

type Observer interface {
DidCommitBlock(block.Height, Shard)
DidReceiveSufficientNilPrevotes(messages process.Messages, threshold int)
DidReceiveSufficientNilPrevotes(messages process.Messages, f int)
IsSignatory(Shard) bool
}

Expand Down Expand Up @@ -222,9 +222,9 @@ func (rebaser *shardRebaser) DidCommitBlock(height block.Height) {
}
}

func (rebaser *shardRebaser) DidReceiveSufficientNilPrevotes(messages process.Messages, threshold int) {
func (rebaser *shardRebaser) DidReceiveSufficientNilPrevotes(messages process.Messages, f int) {
if rebaser.observer != nil {
rebaser.observer.DidReceiveSufficientNilPrevotes(messages, threshold)
rebaser.observer.DidReceiveSufficientNilPrevotes(messages, f)
}
}

Expand Down

0 comments on commit 32a55d2

Please sign in to comment.