From 4aec90fe2a90438af156928e9438bb91b332a5e1 Mon Sep 17 00:00:00 2001 From: Daniil Lashin Date: Tue, 30 Apr 2019 20:50:43 +0300 Subject: [PATCH] Fix empty frozen funds case --- CHANGELOG.md | 6 ++++++ core/state/statedb.go | 39 +++++++++++++++++++++------------------ version/version.go | 4 ++-- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca0ecdbe..177acf274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.20.4 + +BUG FIXES + +- [core] Fix empty frozen funds case + ## 0.20.3 BUG FIXES diff --git a/core/state/statedb.go b/core/state/statedb.go index 6511a4be3..286fb2e4e 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1677,30 +1677,33 @@ func (s *StateDB) deleteCoin(symbol types.CoinSymbol) { // remove coin from frozen funds for _, height := range frozenFundsHeights { frozenFunds := s.GetStateFrozenFunds(height) - var newFrozenFundsList []FrozenFund - for _, ff := range frozenFunds.data.List { - if ff.Coin == symbol { - ret := formula.CalculateSaleReturn(coinToDelete.Volume(), coinToDelete.ReserveBalance(), 100, ff.Value) + if frozenFunds != nil { + var newFrozenFundsList []FrozenFund - coinToDelete.SubReserve(ret) - coinToDelete.SubVolume(ff.Value) + for _, ff := range frozenFunds.data.List { + if ff.Coin == symbol { + ret := formula.CalculateSaleReturn(coinToDelete.Volume(), coinToDelete.ReserveBalance(), 100, ff.Value) - newFrozenFundsList = append(newFrozenFundsList, FrozenFund{ - Address: ff.Address, - CandidateKey: ff.CandidateKey, - Coin: types.GetBaseCoin(), - Value: ret, - }) + coinToDelete.SubReserve(ret) + coinToDelete.SubVolume(ff.Value) - continue + newFrozenFundsList = append(newFrozenFundsList, FrozenFund{ + Address: ff.Address, + CandidateKey: ff.CandidateKey, + Coin: types.GetBaseCoin(), + Value: ret, + }) + + continue + } + + newFrozenFundsList = append(newFrozenFundsList, ff) } - newFrozenFundsList = append(newFrozenFundsList, ff) + frozenFunds.data.List = newFrozenFundsList + s.setStateFrozenFunds(frozenFunds) + s.MarkStateFrozenFundsDirty(frozenFunds.blockHeight) } - - frozenFunds.data.List = newFrozenFundsList - s.setStateFrozenFunds(frozenFunds) - s.MarkStateFrozenFundsDirty(frozenFunds.blockHeight) } // remove coin from stakes diff --git a/version/version.go b/version/version.go index accc57bfa..b155cc2c2 100755 --- a/version/version.go +++ b/version/version.go @@ -4,14 +4,14 @@ package version const ( Maj = "0" Min = "20" - Fix = "3" + Fix = "4" AppVer = 4 ) var ( // Must be a string because scripts like dist.sh read this file. - Version = "0.20.3" + Version = "0.20.4" // GitCommit is the current HEAD set using ldflags. GitCommit string