Skip to content

Commit 2b3842c

Browse files
authored
Merge pull request #3165 from cosmos/cwgoes/gos-patch-1
GoS point release
2 parents ac511ab + 3387261 commit 2b3842c

File tree

12 files changed

+79
-36
lines changed

12 files changed

+79
-36
lines changed

CHANGELOG.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
# Changelog
22

3+
## 0.29.0
4+
5+
BREAKING CHANGES
6+
7+
* Gaia
8+
* [\#3148](https://github.com/cosmos/cosmos-sdk/issues/3148) Fix `gaiad export` by adding a boolean to `NewGaiaApp` determining whether or not to load the latest version
9+
10+
* SDK
11+
* [\#3163](https://github.com/cosmos/cosmos-sdk/issues/3163) Withdraw commission on self bond removal
12+
13+
314
## 0.28.1
415

5-
BREAKNG CHANGES
16+
BREAKING CHANGES
617

718
* Gaia REST API (`gaiacli advanced rest-server`)
819
* [lcd] [\#3045](https://github.com/cosmos/cosmos-sdk/pull/3045) Fix quoted json return on GET /keys (keys list)
@@ -25,11 +36,11 @@ FEATURES
2536
IMPROVEMENTS
2637

2738
* Gaia REST API (`gaiacli advanced rest-server`)
28-
* \#2879, \#2880 Update deposit and vote endpoints to perform a direct txs query
39+
* [\#2879](https://github.com/cosmos/cosmos-sdk/issues/2879), [\#2880](https://github.com/cosmos/cosmos-sdk/issues/2880) Update deposit and vote endpoints to perform a direct txs query
2940
when a given proposal is inactive and thus having votes and deposits removed
3041
from state.
3142
* Gaia CLI (`gaiacli`)
32-
* \#2879, \#2880 Update deposit and vote CLI commands to perform a direct txs query
43+
* [\#2879](https://github.com/cosmos/cosmos-sdk/issues/2879), [\#2880](https://github.com/cosmos/cosmos-sdk/issues/2880) Update deposit and vote CLI commands to perform a direct txs query
3344
when a given proposal is inactive and thus having votes and deposits removed
3445
from state.
3546
* Gaia

client/lcd/test_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func InitializeTestLCD(
230230
privVal.Reset()
231231

232232
db := dbm.NewMemDB()
233-
app := gapp.NewGaiaApp(logger, db, nil)
233+
app := gapp.NewGaiaApp(logger, db, nil, true)
234234
cdc = gapp.MakeCodec()
235235

236236
genesisFile := config.GenesisFile()

cmd/gaia/app/app.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type GaiaApp struct {
6868
}
6969

7070
// NewGaiaApp returns a reference to an initialized GaiaApp.
71-
func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp {
71+
func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp {
7272
cdc := MakeCodec()
7373

7474
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
@@ -167,9 +167,11 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
167167
app.MountStoresTransient(app.tkeyParams, app.tkeyStake, app.tkeyDistr)
168168
app.SetEndBlocker(app.EndBlocker)
169169

170-
err := app.LoadLatestVersion(app.keyMain)
171-
if err != nil {
172-
cmn.Exit(err.Error())
170+
if loadLatest {
171+
err := app.LoadLatestVersion(app.keyMain)
172+
if err != nil {
173+
cmn.Exit(err.Error())
174+
}
173175
}
174176

175177
return app

cmd/gaia/app/app_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
5050

5151
func TestGaiadExport(t *testing.T) {
5252
db := db.NewMemDB()
53-
gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil)
53+
gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true)
5454
setGenesis(gapp)
5555

5656
// Making a new app object with the db, so that initchain hasn't been called
57-
newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil)
57+
newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true)
5858
_, _, err := newGapp.ExportAppStateAndValidators(false)
5959
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
6060
}

cmd/gaia/app/sim_test.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
8787
VotingPeriod: vp,
8888
},
8989
TallyParams: gov.TallyParams{
90-
Threshold: sdk.NewDecWithPrec(5, 1),
91-
Veto: sdk.NewDecWithPrec(334, 3),
90+
Threshold: sdk.NewDecWithPrec(5, 1),
91+
Veto: sdk.NewDecWithPrec(334, 3),
92+
GovernancePenalty: sdk.NewDecWithPrec(1, 2),
9293
},
9394
}
9495
fmt.Printf("Selected randomly generated governance parameters:\n\t%+v\n", govGenesis)
@@ -214,7 +215,7 @@ func BenchmarkFullGaiaSimulation(b *testing.B) {
214215
db.Close()
215216
os.RemoveAll(dir)
216217
}()
217-
app := NewGaiaApp(logger, db, nil)
218+
app := NewGaiaApp(logger, db, nil, true)
218219

219220
// Run randomized simulation
220221
// TODO parameterize numbers, save for a later PR
@@ -256,7 +257,7 @@ func TestFullGaiaSimulation(t *testing.T) {
256257
db.Close()
257258
os.RemoveAll(dir)
258259
}()
259-
app := NewGaiaApp(logger, db, nil, fauxMerkleModeOpt)
260+
app := NewGaiaApp(logger, db, nil, true, fauxMerkleModeOpt)
260261
require.Equal(t, "GaiaApp", app.Name())
261262

262263
// Run randomized simulation
@@ -297,7 +298,7 @@ func TestGaiaImportExport(t *testing.T) {
297298
db.Close()
298299
os.RemoveAll(dir)
299300
}()
300-
app := NewGaiaApp(logger, db, nil, fauxMerkleModeOpt)
301+
app := NewGaiaApp(logger, db, nil, true, fauxMerkleModeOpt)
301302
require.Equal(t, "GaiaApp", app.Name())
302303

303304
// Run randomized simulation
@@ -333,7 +334,7 @@ func TestGaiaImportExport(t *testing.T) {
333334
newDB.Close()
334335
os.RemoveAll(newDir)
335336
}()
336-
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, fauxMerkleModeOpt)
337+
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, fauxMerkleModeOpt)
337338
require.Equal(t, "GaiaApp", newApp.Name())
338339
var genesisState GenesisState
339340
err = app.cdc.UnmarshalJSON(appState, &genesisState)
@@ -393,7 +394,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
393394
db.Close()
394395
os.RemoveAll(dir)
395396
}()
396-
app := NewGaiaApp(logger, db, nil, fauxMerkleModeOpt)
397+
app := NewGaiaApp(logger, db, nil, true, fauxMerkleModeOpt)
397398
require.Equal(t, "GaiaApp", app.Name())
398399

399400
// Run randomized simulation
@@ -435,7 +436,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
435436
newDB.Close()
436437
os.RemoveAll(newDir)
437438
}()
438-
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, fauxMerkleModeOpt)
439+
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, fauxMerkleModeOpt)
439440
require.Equal(t, "GaiaApp", newApp.Name())
440441
newApp.InitChain(abci.RequestInitChain{
441442
AppStateBytes: appState,
@@ -470,7 +471,7 @@ func TestAppStateDeterminism(t *testing.T) {
470471
for j := 0; j < numTimesToRunPerSeed; j++ {
471472
logger := log.NewNopLogger()
472473
db := dbm.NewMemDB()
473-
app := NewGaiaApp(logger, db, nil)
474+
app := NewGaiaApp(logger, db, nil, true)
474475

475476
// Run randomized simulation
476477
simulation.SimulateFromSeed(

cmd/gaia/cmd/gaiad/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func main() {
5555
}
5656

5757
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
58-
return app.NewGaiaApp(logger, db, traceStore,
58+
return app.NewGaiaApp(logger, db, traceStore, true,
5959
baseapp.SetPruning(viper.GetString("pruning")),
6060
baseapp.SetMinimumFees(viper.GetString("minimum_fees")),
6161
)
@@ -64,7 +64,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
6464
func exportAppStateAndTMValidators(
6565
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool,
6666
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
67-
gApp := app.NewGaiaApp(logger, db, traceStore)
67+
gApp := app.NewGaiaApp(logger, db, traceStore, false)
6868
if height != -1 {
6969
err := gApp.LoadHeight(height)
7070
if err != nil {

cmd/gaia/cmd/gaiareplay/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func run(rootDir string) {
105105
// Application
106106
fmt.Println("Creating application")
107107
myapp := app.NewGaiaApp(
108-
ctx.Logger, appDB, traceStoreWriter,
108+
ctx.Logger, appDB, traceStoreWriter, true,
109109
baseapp.SetPruning("everything"), // nothing
110110
)
111111

cmd/logjack/main.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
cmn "github.com/tendermint/tendermint/libs/common"
1313
)
1414

15+
//nolint
1516
const Version = "0.0.2"
1617
const sleepSeconds = 1 // Every second
1718
const readBufferSize = 1024 // 1KB at a time
@@ -24,7 +25,7 @@ func parseFlags() (headPath string, chopSize int64, limitSize int64, version boo
2425
flagSet.StringVar(&chopSizeStr, "chop", "100M", "Move file if greater than this")
2526
flagSet.StringVar(&limitSizeStr, "limit", "10G", "Only keep this much (for each specified file). Remove old files.")
2627
flagSet.BoolVar(&version, "version", false, "Version")
27-
flagSet.Parse(os.Args[1:])
28+
flagSet.Parse(os.Args[1:]) //nolint
2829
chopSize = parseBytesize(chopSizeStr)
2930
limitSize = parseBytesize(limitSizeStr)
3031
return
@@ -59,10 +60,10 @@ func main() {
5960
buf := make([]byte, readBufferSize)
6061
for {
6162
n, err := os.Stdin.Read(buf)
62-
group.Write(buf[:n])
63-
group.Flush()
63+
group.Write(buf[:n]) //nolint
64+
group.Flush() //nolint
6465
if err != nil {
65-
group.Stop()
66+
group.Stop() //nolint
6667
if err == io.EOF {
6768
os.Exit(0)
6869
} else {

x/distribution/keeper/hooks.go

+11
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ func (k Keeper) onDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddre
8787
// Withdrawal all validator distribution rewards and cleanup the distribution record
8888
func (k Keeper) onDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress,
8989
valAddr sdk.ValAddress) {
90+
// Withdraw validator commission when validator self-bond is removed.
91+
// Because we maintain the invariant that all delegations must be removed
92+
// before a validator is deleted, this ensures that commission will be withdrawn
93+
// before the validator is deleted (and the corresponding ValidatorDistInfo removed).
94+
// If we change other parts of the code such that a self-delegation might remain after
95+
// a validator is deleted, this logic will no longer be safe.
96+
// TODO: Consider instead implementing this in a "BeforeValidatorRemoved" hook.
97+
if valAddr.Equals(sdk.ValAddress(delAddr)) {
98+
feePool, commission := k.withdrawValidatorCommission(ctx, valAddr)
99+
k.WithdrawToDelegator(ctx, feePool, delAddr, commission)
100+
}
90101

91102
k.RemoveDelegationDistInfo(ctx, delAddr, valAddr)
92103
}

x/distribution/keeper/validator.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func (k Keeper) RemoveValidatorDistInfo(ctx sdk.Context, valAddr sdk.ValAddress)
4242
if vdi.DelAccum.Accum.IsPositive() {
4343
panic("Should not delete validator with unwithdrawn delegator accum")
4444
}
45+
if !vdi.ValCommission.IsZero() {
46+
panic("Should not delete validator with unwithdrawn validator commission")
47+
}
4548

4649
store := ctx.KVStore(k.storeKey)
4750
store.Delete(GetValidatorDistInfoKey(valAddr))
@@ -119,6 +122,15 @@ func (k Keeper) takeValidatorFeePoolRewards(ctx sdk.Context, operatorAddr sdk.Va
119122
return nil
120123
}
121124

125+
func (k Keeper) withdrawValidatorCommission(ctx sdk.Context, operatorAddr sdk.ValAddress) (types.FeePool, types.DecCoins) {
126+
valInfo := k.GetValidatorDistInfo(ctx, operatorAddr)
127+
wc := k.GetWithdrawContext(ctx, operatorAddr)
128+
valInfo, feePool, commission := valInfo.WithdrawCommission(wc)
129+
k.SetValidatorDistInfo(ctx, valInfo)
130+
131+
return feePool, commission
132+
}
133+
122134
// withdrawal all the validator rewards including the commission
123135
func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.ValAddress) sdk.Error {
124136
if !k.HasValidatorDistInfo(ctx, operatorAddr) {
@@ -130,11 +142,8 @@ func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.Va
130142
withdraw := k.withdrawDelegationRewardsAll(ctx, accAddr)
131143

132144
// withdrawal validator commission rewards
133-
valInfo := k.GetValidatorDistInfo(ctx, operatorAddr)
134-
wc := k.GetWithdrawContext(ctx, operatorAddr)
135-
valInfo, feePool, commission := valInfo.WithdrawCommission(wc)
145+
feePool, commission := k.withdrawValidatorCommission(ctx, operatorAddr)
136146
withdraw = withdraw.Plus(commission)
137-
k.SetValidatorDistInfo(ctx, valInfo)
138147

139148
k.WithdrawToDelegator(ctx, feePool, accAddr, withdraw)
140149
return nil

x/gov/genesis.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ func DefaultGenesisState() GenesisState {
5252
VotingPeriod: time.Duration(172800) * time.Second,
5353
},
5454
TallyParams: TallyParams{
55-
Quorum: sdk.NewDecWithPrec(334, 3),
56-
Threshold: sdk.NewDecWithPrec(5, 1),
57-
Veto: sdk.NewDecWithPrec(334, 3),
55+
Quorum: sdk.NewDecWithPrec(334, 3),
56+
Threshold: sdk.NewDecWithPrec(5, 1),
57+
Veto: sdk.NewDecWithPrec(334, 3),
58+
GovernancePenalty: sdk.NewDecWithPrec(1, 2),
5859
},
5960
}
6061
}
@@ -73,6 +74,12 @@ func ValidateGenesis(data GenesisState) error {
7374
veto.String())
7475
}
7576

77+
govPenalty := data.TallyParams.GovernancePenalty
78+
if govPenalty.IsNegative() || govPenalty.GT(sdk.OneDec()) {
79+
return fmt.Errorf("Governance vote veto threshold should be positive and less or equal to one, is %s",
80+
govPenalty.String())
81+
}
82+
7683
if data.DepositParams.MaxDepositPeriod > data.VotingParams.VotingPeriod {
7784
return fmt.Errorf("Governance deposit period should be less than or equal to the voting period (%ds), is %ds",
7885
data.VotingParams.VotingPeriod, data.DepositParams.MaxDepositPeriod)

x/gov/params.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ type DepositParams struct {
1414

1515
// Param around Tallying votes in governance
1616
type TallyParams struct {
17-
Quorum sdk.Dec `json:"quorum"` // Minimum percentage of total stake needed to vote for a result to be considered valid
18-
Threshold sdk.Dec `json:"threshold"` // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
19-
Veto sdk.Dec `json:"veto"` // Minimum value of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3
17+
Quorum sdk.Dec `json:"quorum"` // Minimum percentage of total stake needed to vote for a result to be considered valid
18+
Threshold sdk.Dec `json:"threshold"` // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
19+
Veto sdk.Dec `json:"veto"` // Minimum value of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3
20+
GovernancePenalty sdk.Dec `json:"governance_penalty"` // Penalty if validator does not vote
2021
}
2122

2223
// Param around Voting in governance

0 commit comments

Comments
 (0)