Skip to content

Commit

Permalink
Add grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Oct 12, 2020
1 parent 89508e2 commit 3310d48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/state/validators/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/MinterTeam/minter-go-node/core/types"
"github.com/MinterTeam/minter-go-node/rlp"
"github.com/MinterTeam/minter-go-node/tree"
"github.com/MinterTeam/minter-go-node/upgrades"

"math/big"
)
Expand Down Expand Up @@ -101,7 +102,10 @@ func (v *Validators) SetValidatorAbsent(height uint64, address types.TmAddress)
validator.SetAbsent(height)

if validator.CountAbsentTimes() > ValidatorMaxAbsentTimes {
v.punishValidator(height, address)
if !upgrades.IsGraceBlock(height) {
v.punishValidator(height, address)
}

v.turnValidatorOff(address)
}
}
Expand Down
28 changes: 28 additions & 0 deletions upgrades/grace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package upgrades

var gracePeriods = []*gracePeriod{
newGracePeriod(1, 120),
}

func IsGraceBlock(block uint64) bool {
for _, gp := range gracePeriods {
if gp.isApplicable(block) {
return true
}
}

return false
}

type gracePeriod struct {
from uint64
to uint64
}

func (gp *gracePeriod) isApplicable(block uint64) bool {
return block >= gp.from && block <= gp.to
}

func newGracePeriod(from uint64, to uint64) *gracePeriod {
return &gracePeriod{from: from, to: to}
}

0 comments on commit 3310d48

Please sign in to comment.