Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbft: adjust timer setting by the block processing time #46

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (d *DBFT) checkCommit() {
return
}

d.lastBlockIndex = d.BlockIndex
d.lastBlockTime = d.Timer.Now()
d.block = d.CreateBlock()
hash := d.block.Hash()

Expand Down
4 changes: 4 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dbft

import (
"math/rand"
"time"

"github.com/nspcc-dev/dbft/block"
"github.com/nspcc-dev/dbft/crypto"
Expand Down Expand Up @@ -63,6 +64,9 @@ type Context struct {
// LastSeenMessage array stores the height of the last seen message, for each validator.
// if this node never heard from validator i, LastSeenMessage[i] will be -1.
LastSeenMessage []*timer.HV

lastBlockTime time.Time
lastBlockIndex uint32
}

// N returns total number of validators.
Expand Down
8 changes: 8 additions & 0 deletions dbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ func (d *DBFT) InitializeConsensus(view byte) {
} else {
timeout = d.SecondsPerBlock << (d.ViewNumber + 1)
}
if d.lastBlockIndex+1 == d.BlockIndex {
var ts = d.Timer.Now()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var x = -> x := ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¡No me gusta :=! Not that it's that big of a problem, though.

var diff = ts.Sub(d.lastBlockTime)
timeout -= diff
if timeout < 0 {
timeout = 0
}
}
d.changeTimer(timeout)
}

Expand Down