Skip to content

Commit

Permalink
Merge PR #5418: RC1 v0.37.5 Cherry Picks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Dec 19, 2019
1 parent c257487 commit 7f433a7
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 71 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v0.37.5] - TBD

### Features

* (types) [\#5360](https://github.com/cosmos/cosmos-sdk/pull/5360) Implement `SortableDecBytes` which
allows the `Dec` type be sortable.

### Improvements

* (tendermint) Bump Tendermint version to [v0.32.8](https://github.com/tendermint/tendermint/releases/tag/v0.32.8)

### Bug Fixes

* (iavl) [\#5276](https://github.com/cosmos/cosmos-sdk/issues/5276) Fix potential race condition in `iavlIterator#Close`.
* (baseapp) [\#5350](https://github.com/cosmos/cosmos-sdk/issues/5350) Allow a node to restart successfully
after a `halt-height` or `halt-time` has been triggered.
* (types) [\#5395](https://github.com/cosmos/cosmos-sdk/issues/5395) Fix `Uint#LTE`.
* (types) [\#5408](https://github.com/cosmos/cosmos-sdk/issues/5408) `NewDecCoins` constructor now sorts the coins.

## [v0.37.4] - 2019-11-04

### Improvements
Expand Down Expand Up @@ -2578,7 +2597,8 @@ BUG FIXES:
<!-- Release links -->
[Unreleased]: https://github.com/cosmos/cosmos-sdk/compare/v0.37.4...HEAD
[Unreleased]: https://github.com/cosmos/cosmos-sdk/compare/v0.37.5...HEAD
[v0.37.5]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.5
[v0.37.4]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.4
[v0.37.3]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.3
[v0.37.1]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.1
Expand Down
36 changes: 18 additions & 18 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,24 +995,6 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc
func (app *BaseApp) Commit() (res abci.ResponseCommit) {
header := app.deliverState.ctx.BlockHeader()

var halt bool

switch {
case app.haltHeight > 0 && uint64(header.Height) >= app.haltHeight:
halt = true

case app.haltTime > 0 && header.Time.Unix() >= int64(app.haltTime):
halt = true
}

if halt {
app.halt()

// Note: State is not actually committed when halted. Logs from Tendermint
// can be ignored.
return abci.ResponseCommit{}
}

// Write the DeliverTx state which is cache-wrapped and commit the MultiStore.
// The write to the DeliverTx state writes all state transitions to the root
// MultiStore (app.cms) so when Commit() is called is persists those values.
Expand All @@ -1029,6 +1011,24 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) {
// empty/reset the deliver state
app.deliverState = nil

var halt bool

switch {
case app.haltHeight > 0 && uint64(header.Height) >= app.haltHeight:
halt = true

case app.haltTime > 0 && header.Time.Unix() >= int64(app.haltTime):
halt = true
}

if halt {
// Halt the binary and allow Tendermint to receive the ResponseCommit
// response with the commit ID hash. This will allow the node to successfully
// restart and process blocks assuming the halt configuration has been
// reset or moved to a more distant value.
app.halt()
}

return abci.ResponseCommit{
Data: commitID.Hash,
}
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/cosmos/ledger-cosmos-go v0.10.3
github.com/gogo/protobuf v1.3.0
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
github.com/gorilla/mux v1.7.0
github.com/mattn/go-isatty v0.0.6
Expand All @@ -18,15 +18,14 @@ require (
github.com/spf13/afero v1.2.1 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.4.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.4.0
github.com/stumble/gorocksdb v0.0.3 // indirect
github.com/tendermint/btcd v0.1.1
github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5
github.com/tendermint/go-amino v0.15.0
github.com/tendermint/iavl v0.12.4
github.com/tendermint/tendermint v0.32.7
github.com/tendermint/tendermint v0.32.8
github.com/tendermint/tm-db v0.2.0
gopkg.in/yaml.v2 v2.2.2
gopkg.in/yaml.v2 v2.2.7
)
56 changes: 43 additions & 13 deletions go.sum

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ type BaseConfig struct {
// HaltHeight contains a non-zero block height at which a node will gracefully
// halt and shutdown that can be used to assist upgrades and testing.
//
// Note: State will not be committed on the corresponding height and any logs
// indicating such can be safely ignored.
// Note: Commitment of state will be attempted on the corresponding block.
HaltHeight uint64 `mapstructure:"halt-height"`

// HaltTime contains a non-zero minimum block time (in Unix seconds) at which
// a node will gracefully halt and shutdown that can be used to assist
// upgrades and testing.
//
// Note: State will not be committed on the corresponding height and any logs
// indicating such can be safely ignored.
// Note: Commitment of state will be attempted on the corresponding block.
HaltTime uint64 `mapstructure:"halt-time"`
}

Expand Down
6 changes: 2 additions & 4 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}"
# HaltHeight contains a non-zero block height at which a node will gracefully
# halt and shutdown that can be used to assist upgrades and testing.
#
# Note: State will not be committed on the corresponding height and any logs
# indicating such can be safely ignored.
# Note: Commitment of state will be attempted on the corresponding block.
halt-height = {{ .BaseConfig.HaltHeight }}
# HaltTime contains a non-zero minimum block time (in Unix seconds) at which
# a node will gracefully halt and shutdown that can be used to assist upgrades
# and testing.
#
# Note: State will not be committed on the corresponding height and any logs
# indicating such can be safely ignored.
# Note: Commitment of state will be attempted on the corresponding block.
halt-time = {{ .BaseConfig.HaltTime }}
`

Expand Down
6 changes: 5 additions & 1 deletion store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,13 @@ func (iter *iavlIterator) Value() []byte {
return val
}

// Implements types.Iterator.
// Close closes the IAVL iterator by closing the quit channel and waiting for
// the iterCh to finish/close.
func (iter *iavlIterator) Close() {
close(iter.quitCh)
// wait iterCh to close
for range iter.iterCh {
}
}

//----------------------------------------
Expand Down
59 changes: 37 additions & 22 deletions types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import (
// ----------------------------------------------------------------------------
// Decimal Coin

// Coins which can have additional decimal points
// DecCoin defines a coin which can have additional decimal points
type DecCoin struct {
Denom string `json:"denom"`
Amount Dec `json:"amount"`
}

// NewDecCoin creates a new DecCoin instance from an Int.
func NewDecCoin(denom string, amount Int) DecCoin {
mustValidateDenom(denom)

if amount.LT(ZeroInt()) {
panic(fmt.Sprintf("negative coin amount: %v\n", amount))
if err := validate(denom, amount); err != nil {
panic(err)
}

return DecCoin{
Expand All @@ -30,6 +29,7 @@ func NewDecCoin(denom string, amount Int) DecCoin {
}
}

// NewDecCoinFromDec creates a new DecCoin instance from a Dec.
func NewDecCoinFromDec(denom string, amount Dec) DecCoin {
mustValidateDenom(denom)

Expand All @@ -43,12 +43,10 @@ func NewDecCoinFromDec(denom string, amount Dec) DecCoin {
}
}

// NewDecCoinFromCoin creates a new DecCoin from a Coin.
func NewDecCoinFromCoin(coin Coin) DecCoin {
if coin.Amount.LT(ZeroInt()) {
panic(fmt.Sprintf("negative decimal coin amount: %v\n", coin.Amount))
}
if strings.ToLower(coin.Denom) != coin.Denom {
panic(fmt.Sprintf("denom cannot contain upper case characters: %s\n", coin.Denom))
if err := validate(coin.Denom, coin.Amount); err != nil {
panic(err)
}

return DecCoin{
Expand Down Expand Up @@ -97,28 +95,32 @@ func (coin DecCoin) IsEqual(other DecCoin) bool {
return coin.Amount.Equal(other.Amount)
}

// Adds amounts of two coins with same denom
// Add adds amounts of two decimal coins with same denom.
func (coin DecCoin) Add(coinB DecCoin) DecCoin {
if coin.Denom != coinB.Denom {
panic(fmt.Sprintf("coin denom different: %v %v\n", coin.Denom, coinB.Denom))
}
return DecCoin{coin.Denom, coin.Amount.Add(coinB.Amount)}
}

// Subtracts amounts of two coins with same denom
// Sub subtracts amounts of two decimal coins with same denom.
func (coin DecCoin) Sub(coinB DecCoin) DecCoin {
if coin.Denom != coinB.Denom {
panic(fmt.Sprintf("coin denom different: %v %v\n", coin.Denom, coinB.Denom))
}
return DecCoin{coin.Denom, coin.Amount.Sub(coinB.Amount)}
res := DecCoin{coin.Denom, coin.Amount.Sub(coinB.Amount)}
if res.IsNegative() {
panic("negative decimal coin amount")
}
return res
}

// TruncateDecimal returns a Coin with a truncated decimal and a DecCoin for the
// change. Note, the change may be zero.
func (coin DecCoin) TruncateDecimal() (Coin, DecCoin) {
truncated := coin.Amount.TruncateInt()
change := coin.Amount.Sub(truncated.ToDec())
return NewCoin(coin.Denom, truncated), DecCoin{coin.Denom, change}
return NewCoin(coin.Denom, truncated), NewDecCoinFromDec(coin.Denom, change)
}

// IsPositive returns true if coin amount is positive.
Expand All @@ -141,18 +143,31 @@ func (coin DecCoin) String() string {
return fmt.Sprintf("%v%v", coin.Amount, coin.Denom)
}

// IsValid returns true if the DecCoin has a non-negative amount and the denom
// is valid.
func (coin DecCoin) IsValid() bool {
if err := validateDenom(coin.Denom); err != nil {
return false
}
return !coin.IsNegative()
}

// ----------------------------------------------------------------------------
// Decimal Coins

// coins with decimal
// DecCoins defines a slice of coins with decimal values
type DecCoins []DecCoin

// NewDecCoins constructs a new coin set with decimal values
// from regular Coins.
func NewDecCoins(coins Coins) DecCoins {
dcs := make(DecCoins, len(coins))
for i, coin := range coins {
dcs[i] = NewDecCoinFromCoin(coin)
decCoins := make(DecCoins, len(coins))
newCoins := NewCoins(coins...)
for i, coin := range newCoins {
decCoins[i] = NewDecCoinFromCoin(coin)
}
return dcs

return decCoins
}

// String implements the Stringer interface for DecCoins. It returns a
Expand All @@ -177,7 +192,7 @@ func (coins DecCoins) TruncateDecimal() (truncatedCoins Coins, changeCoins DecCo
for _, coin := range coins {
truncated, change := coin.TruncateDecimal()
if !truncated.IsZero() {
truncatedCoins = truncatedCoins.Add(Coins{truncated})
truncatedCoins = truncatedCoins.Add(NewCoins(truncated))
}
if !change.IsZero() {
changeCoins = changeCoins.Add(DecCoins{change})
Expand Down Expand Up @@ -404,7 +419,7 @@ func (coins DecCoins) Empty() bool {
return len(coins) == 0
}

// returns the amount of a denom from deccoins
// AmountOf returns the amount of a denom from deccoins
func (coins DecCoins) AmountOf(denom string) Dec {
mustValidateDenom(denom)

Expand Down Expand Up @@ -451,7 +466,7 @@ func (coins DecCoins) IsEqual(coinsB DecCoins) bool {
return true
}

// return whether all coins are zero
// IsZero returns whether all coins are zero
func (coins DecCoins) IsZero() bool {
for _, coin := range coins {
if !coin.Amount.IsZero() {
Expand Down
Loading

0 comments on commit 7f433a7

Please sign in to comment.