Skip to content

Commit

Permalink
Merge pull request #275 from MinterTeam/fix
Browse files Browse the repository at this point in the history
Hot fixes
  • Loading branch information
danil-lashin authored Jan 22, 2020
2 parents 1443924 + 5ca4a7f commit 706fd5d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 44 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 1.0.5

BUG FIXES

- [core] Fix coin liquidation issue

IMPROVEMENT

- [core] Add grace period from 4262457 to 4262500 block
- [cmd] Set start time at 7:00 AM Wednesday, January 22, 2020
- [config] Add halt_height param

## 1.0.4

IMPROVEMENT
Expand Down
2 changes: 1 addition & 1 deletion cmd/minter/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var RunNode = &cobra.Command{

func runNode() error {
now := time.Now()
startTime := time.Date(2019, time.June, 5, 17, 0, 0, 0, time.UTC)
startTime := time.Date(2020, time.January, 22, 7, 0, 0, 0, time.UTC)
if startTime.After(now) {
fmt.Printf("Start time is in the future, sleeping until %s", startTime)
time.Sleep(startTime.Sub(now))
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ type BaseConfig struct {
APISimultaneousRequests int `mapstructure:"api_simultaneous_requests"`

LogPath string `mapstructure:"log_path"`

HaltHeight int `mapstructure:"halt_height"`
}

// DefaultBaseConfig returns a default base configuration for a Tendermint node
Expand Down
10 changes: 10 additions & 0 deletions core/minter/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package minter

import (
"bytes"
"fmt"
"github.com/MinterTeam/go-amino"
"github.com/MinterTeam/minter-go-node/cmd/utils"
"github.com/MinterTeam/minter-go-node/config"
Expand Down Expand Up @@ -65,6 +66,8 @@ type Blockchain struct {
lock sync.RWMutex
wg sync.WaitGroup // wg is used for graceful node shutdown
stopped uint32

haltHeight uint64
}

// Creates Minter Blockchain instance, should be only called once
Expand Down Expand Up @@ -96,6 +99,8 @@ func NewMinterBlockchain(cfg *config.Config) *Blockchain {
rewards.SetStartHeight(applicationDB.GetStartHeight())
validators.SetStartHeight(applicationDB.GetStartHeight())

blockchain.haltHeight = uint64(cfg.HaltHeight)

return blockchain
}

Expand Down Expand Up @@ -154,6 +159,11 @@ func (app *Blockchain) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.Res
}
}

if app.haltHeight > 0 && height >= app.haltHeight {
app.wg.Done()
panic(fmt.Sprintf("Application halted at height %d", height))
}

// compute max gas
app.updateBlocksTimeDelta(height, 3)
maxGas := app.calcMaxGas(height)
Expand Down
98 changes: 57 additions & 41 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ func (s *StateDB) SetValidatorAbsent(address [20]byte) {
for i := range vals.data {
validator := &vals.data[i]
if validator.GetAddress() == address {

var coinsToSanitize []types.CoinSymbol
candidates := s.getStateCandidates()

var candidate *Candidate
Expand All @@ -1252,55 +1252,71 @@ func (s *StateDB) SetValidatorAbsent(address [20]byte) {

validator.AbsentTimes.SetIndex(int(s.height)%ValidatorMaxAbsentWindow, true)

isGracePeriod := false
if s.height > upgrades.GracePeriod1From && s.height < upgrades.GracePeriod1To {
isGracePeriod = true
}

if validator.CountAbsentTimes() > ValidatorMaxAbsentTimes {
candidate.Status = CandidateStatusOffline
validator.AbsentTimes = types.NewBitArray(ValidatorMaxAbsentWindow)
validator.toDrop = true

totalStake := big.NewInt(0)

for j, stake := range candidate.Stakes {
newValue := big.NewInt(0).Set(stake.Value)
newValue.Mul(newValue, big.NewInt(99))
newValue.Div(newValue, big.NewInt(100))

slashed := big.NewInt(0).Set(stake.Value)
slashed.Sub(slashed, newValue)

if !stake.Coin.IsBaseCoin() {
coin := s.GetStateCoin(stake.Coin).Data()
ret := formula.CalculateSaleReturn(coin.Volume, coin.ReserveBalance, coin.Crr, slashed)

s.SubCoinVolume(coin.Symbol, slashed)
s.SubCoinReserve(coin.Symbol, ret)
s.SanitizeCoin(stake.Coin)

s.AddTotalSlashed(ret)
} else {
s.AddTotalSlashed(slashed)
if !isGracePeriod {
totalStake := big.NewInt(0)

for j, stake := range candidate.Stakes {
newValue := big.NewInt(0).Set(stake.Value)
newValue.Mul(newValue, big.NewInt(99))
newValue.Div(newValue, big.NewInt(100))

slashed := big.NewInt(0).Set(stake.Value)
slashed.Sub(slashed, newValue)

if !stake.Coin.IsBaseCoin() {
coin := s.GetStateCoin(stake.Coin).Data()
ret := formula.CalculateSaleReturn(coin.Volume, coin.ReserveBalance, coin.Crr, slashed)

s.SubCoinVolume(coin.Symbol, slashed)
s.SubCoinReserve(coin.Symbol, ret)
if s.height <= upgrades.UpgradeBlock2 {
s.SanitizeCoin(stake.Coin)
}
coinsToSanitize = append(coinsToSanitize, stake.Coin)

s.AddTotalSlashed(ret)
} else {
s.AddTotalSlashed(slashed)
}

edb.AddEvent(s.height, events.SlashEvent{
Address: stake.Owner,
Amount: slashed.Bytes(),
Coin: stake.Coin,
ValidatorPubKey: candidate.PubKey,
})

candidate.Stakes[j] = Stake{
Owner: stake.Owner,
Coin: stake.Coin,
Value: newValue,
BipValue: big.NewInt(0),
}
totalStake.Add(totalStake, newValue)
}

edb.AddEvent(s.height, events.SlashEvent{
Address: stake.Owner,
Amount: slashed.Bytes(),
Coin: stake.Coin,
ValidatorPubKey: candidate.PubKey,
})

candidate.Stakes[j] = Stake{
Owner: stake.Owner,
Coin: stake.Coin,
Value: newValue,
BipValue: big.NewInt(0),
}
totalStake.Add(totalStake, newValue)
validator.TotalBipStake = totalStake
}

validator.TotalBipStake = totalStake
}

s.setStateCandidates(candidates)
s.MarkStateCandidateDirty()

if s.height > upgrades.UpgradeBlock2 {
for _, coin := range coinsToSanitize {
s.SanitizeCoin(coin)
}
}
}
}

Expand Down Expand Up @@ -1757,13 +1773,13 @@ func (s *StateDB) deleteCoin(symbol types.CoinSymbol) {
coinToDelete.SubReserve(ret)
coinToDelete.SubVolume(stake.Value)

stake := candidate.GetStakeOfAddress(stake.Owner, types.GetBaseCoin())
if stake == nil {
st := candidate.GetStakeOfAddress(stake.Owner, types.GetBaseCoin())
if st == nil {
candidate.Stakes[j].Value = ret
candidate.Stakes[j].Coin = types.GetBaseCoin()
} else {
candidate.Stakes[j].Value = big.NewInt(0)
stake.Value.Add(stake.Value, ret)
st.Value.Add(st.Value, ret)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions upgrades/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ package upgrades

const UpgradeBlock0 = 5760
const UpgradeBlock1 = 250000
const UpgradeBlock2 = 4262457

const GracePeriod1From = 4262457
const GracePeriod1To = 4262500
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package version
const (
Maj = "1"
Min = "0"
Fix = "4"
Fix = "5"

AppVer = 5
)

var (
// Must be a string because scripts like dist.sh read this file.
Version = "1.0.4"
Version = "1.0.5"

// GitCommit is the current HEAD set using ldflags.
GitCommit string
Expand Down

0 comments on commit 706fd5d

Please sign in to comment.