Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Simulate transactions for fee distribution, simulate inflation, and fix a multitude of bugs discovered in the process of doing so #2501

Merged
merged 58 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1674625
Update PENDING.md
cwgoes Oct 16, 2018
2fff810
This PR now will do something else
cwgoes Oct 16, 2018
67258c4
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 16, 2018
b700107
Add simulated distribution msgs
cwgoes Oct 16, 2018
1d4b595
Correctly set power in vote info
cwgoes Oct 16, 2018
74780c6
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 18, 2018
f527163
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 18, 2018
e099491
Merge PR #2526: Distribution fixes from simulation
cwgoes Oct 18, 2018
06c7e27
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 18, 2018
25ce0de
Update stake module simulation and fix linter errors
cwgoes Oct 18, 2018
42ae267
Simulation fixes work-in-progress
cwgoes Oct 19, 2018
4779359
Linter, enable simulated distribution msgs again
cwgoes Oct 19, 2018
d21f93a
Simulation debugging contd.
cwgoes Oct 19, 2018
c3d3a79
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 19, 2018
375e821
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 19, 2018
22cb698
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 19, 2018
d9916f9
bugfix (#2535)
rigelrozanski Oct 19, 2018
4f719d6
Remove the print statement
cwgoes Oct 19, 2018
6c9ad8c
Add sanity checks
cwgoes Oct 19, 2018
2e8f354
Fixup stake hooks (hopefully...)
cwgoes Oct 19, 2018
843ccaf
Remove comment
cwgoes Oct 19, 2018
1afb5bf
Simulate minting, fix bug where pool was not updated
cwgoes Oct 19, 2018
dc13a0c
Use InflateSupply instead
cwgoes Oct 19, 2018
a6ef3c4
use power instead of total tokens
rigelrozanski Oct 19, 2018
7770aec
Withdraw rewards on bonded to unbonding
cwgoes Oct 19, 2018
255a6a5
Cleanup to one hook
cwgoes Oct 19, 2018
c88fc48
Fix linter issues
cwgoes Oct 19, 2018
c9e5c32
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 19, 2018
3fa5778
Update naming (BondedValidatorIndex->ValidatorsBondedIndex) and add s…
jaekwon Oct 21, 2018
015b829
GetValidatorsBonded -> LastValidators etc
jaekwon Oct 21, 2018
5416af8
LastValidatorPower -> LastValidator
jaekwon Oct 21, 2018
1cc7432
Replicate Rigel's changes but w/ modifications as discussed + some na…
jaekwon Oct 22, 2018
19225fc
Print debugging info
jaekwon Oct 22, 2018
471ddee
tweak debug output
jaekwon Oct 22, 2018
278d237
call hook on slashing
rigelrozanski Oct 22, 2018
a3447cd
debug cleanup
rigelrozanski Oct 22, 2018
c4d7747
Merge remote-tracking branch 'origin/cwgoes/check-supply-in-simulatio…
rigelrozanski Oct 22, 2018
bcc3192
correct LastValidatorPower
rigelrozanski Oct 22, 2018
e088c8b
Merge pull request #2552 from cosmos/jae/check-supply-in-simulation
rigelrozanski Oct 22, 2018
c3008d5
Add more useful logging
jaekwon Oct 22, 2018
7f43860
Merge branch 'cwgoes/check-supply-in-simulation' of github.com:cosmos…
cwgoes Oct 23, 2018
ea565ba
WIP intermediate...
jaekwon Oct 23, 2018
1630c0f
WIP intermediate...
jaekwon Oct 23, 2018
fa3730a
WIP looking for bug...
jaekwon Oct 23, 2018
5a559f7
simulation stop early with no proposers
rigelrozanski Oct 23, 2018
8999ee8
re-enable simulation parameters
rigelrozanski Oct 23, 2018
f82d6a5
Merge pull request #2564 from cosmos/rigel/check-supply-in-simulation2
cwgoes Oct 23, 2018
5790d01
Merge remote-tracking branch 'origin/jae/check-supply-in-simulation2'…
cwgoes Oct 23, 2018
be66a49
Remove debugging print statements
cwgoes Oct 23, 2018
c14fa12
Back to 50 initially bonded
cwgoes Oct 23, 2018
33c8238
Merge branch 'develop' into cwgoes/check-supply-in-simulation
cwgoes Oct 23, 2018
f587b46
Update PENDING.md
cwgoes Oct 23, 2018
6bf7e02
Back to on-operation=false, update PENDING.md
cwgoes Oct 23, 2018
604de85
Remove unnecessary change, clarify amt in sim_test.go
cwgoes Oct 23, 2018
edd56be
Cleanup, additional item in PENDING.md
cwgoes Oct 23, 2018
306fb8f
Address @rigelrozanski comments
cwgoes Oct 23, 2018
cd9373d
Make linter happy
cwgoes Oct 23, 2018
3d270ba
Store last total power as sdk.Int, not sdk.Dec
cwgoes Oct 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove debugging print statements
  • Loading branch information
cwgoes committed Oct 23, 2018
commit be66a4950e7f75e1e3baf929d7e028a5614c645d
11 changes: 0 additions & 11 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,6 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
fmt.Println(
cmn.Cyan(
fmt.Sprintf("BEGIN BLOCK #%v", req.Header.Height),
),
)

if app.cms.TracingEnabled() {
app.cms.ResetTraceContext()
Expand Down Expand Up @@ -678,12 +673,6 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc
res = app.endBlocker(app.deliverState.ctx, req)
}

fmt.Println(
cmn.Cyan(
fmt.Sprintf("END BLOCK"),
),
)

return
}

Expand Down
8 changes: 3 additions & 5 deletions x/distribution/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func (k Keeper) onValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) {
vdi := types.ValidatorDistInfo{
OperatorAddr: addr,
FeePoolWithdrawalHeight: height,
Pool: types.DecCoins{},
PoolCommission: types.DecCoins{},
DelAccum: types.NewTotalAccum(height),
Pool: types.DecCoins{},
PoolCommission: types.DecCoins{},
DelAccum: types.NewTotalAccum(height),
}
k.SetValidatorDistInfo(ctx, vdi)
}
Expand Down Expand Up @@ -54,8 +54,6 @@ func (k Keeper) onDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress,
func (k Keeper) onDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress,
valAddr sdk.ValAddress) {

fmt.Printf("DELEGATION SHARES MODIFIED %v\n", valAddr)

if err := k.WithdrawDelegationReward(ctx, delAddr, valAddr); err != nil {
panic(err)
}
Expand Down
15 changes: 0 additions & 15 deletions x/distribution/types/fee_pool.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
cmn "github.com/tendermint/tendermint/libs/common"
)

// total accumulation tracker
Expand Down Expand Up @@ -39,18 +36,6 @@ func (ta TotalAccum) UpdateForNewHeight_DEBUG(height int64, accumCreatedPerBlock
if blocks < 0 {
panic("reverse updated for new height")
}
if !accumCreatedPerBlock.IsZero() && blocks != 0 {
fmt.Println(
cmn.Blue(
fmt.Sprintf("FP Add %v * %v = %v, + %v (old) => %v (new)",
accumCreatedPerBlock.String(), sdk.NewInt(blocks),
accumCreatedPerBlock.MulInt(sdk.NewInt(blocks)).String(),
ta.Accum.String(),
ta.Accum.Add(accumCreatedPerBlock.MulInt(sdk.NewInt(blocks))).String(),
),
),
)
}
ta.Accum = ta.Accum.Add(accumCreatedPerBlock.MulInt(sdk.NewInt(blocks)))
ta.UpdateHeight = height
return ta
Expand Down
31 changes: 3 additions & 28 deletions x/distribution/types/validator_info.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
cmn "github.com/tendermint/tendermint/libs/common"
)

// distribution info for a particular validator
Expand All @@ -22,9 +19,9 @@ func NewValidatorDistInfo(operatorAddr sdk.ValAddress, currentHeight int64) Vali
return ValidatorDistInfo{
OperatorAddr: operatorAddr,
FeePoolWithdrawalHeight: currentHeight,
Pool: DecCoins{},
PoolCommission: DecCoins{},
DelAccum: NewTotalAccum(currentHeight),
Pool: DecCoins{},
PoolCommission: DecCoins{},
DelAccum: NewTotalAccum(currentHeight),
}
}

Expand All @@ -46,15 +43,6 @@ func (vi ValidatorDistInfo) UpdateTotalDelAccum(height int64, totalDelShares sdk
func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBonded, vdTokens,
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {

if vi.FeePoolWithdrawalHeight != height && !vdTokens.IsZero() {
fmt.Println(
cmn.Yellow(
fmt.Sprintf("TakeFeePoolRewards %v last: %v curr: %v pow: %v",
vi.OperatorAddr, vi.FeePoolWithdrawalHeight, height, vdTokens.String()),
),
)
}

fp = fp.UpdateTotalValAccum(height, totalBonded)

if fp.TotalValAccum.Accum.IsZero() {
Expand All @@ -66,19 +54,6 @@ func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBo
vi.FeePoolWithdrawalHeight = height
accum := vdTokens.MulInt(sdk.NewInt(blocks))

if !accum.IsZero() {
fmt.Println(
cmn.Red(
fmt.Sprintf("FP Sub %v * %v = %v, %v - _ => %v",
vdTokens.String(), sdk.NewInt(blocks),
accum.String(),
fp.TotalValAccum.Accum.String(),
fp.TotalValAccum.Accum.Sub(accum).String(),
),
),
)
}

if accum.GT(fp.TotalValAccum.Accum) {
panic("individual accum should never be greater than the total")
}
Expand Down
2 changes: 0 additions & 2 deletions x/stake/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
// Manually set indices for the first time
keeper.SetValidatorByConsAddr(ctx, validator)
keeper.SetValidatorByPowerIndex(ctx, validator, data.Pool)
fmt.Println("stake.INITGENESIS", ctx.BlockHeight())
keeper.OnValidatorCreated(ctx, validator.OperatorAddr)
}

for _, delegation := range data.Bonds {
keeper.SetDelegation(ctx, delegation)
fmt.Println("stake.INITGENESISd", ctx.BlockHeight())
keeper.OnDelegationCreated(ctx, delegation.DelegatorAddr, delegation.ValidatorAddr)
}

Expand Down
1 change: 0 additions & 1 deletion x/stake/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Co
}

// call the appropriate hook if present
//fmt.Printf("DELEGATION SHARES MODIFIED (2) FOUND OR NOT %v found: %v\n", validator.OperatorAddr, found)
if found {
k.OnDelegationSharesModified(ctx, delAddr, validator.OperatorAddr)
} else {
Expand Down
29 changes: 0 additions & 29 deletions x/stake/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/stake/types"
cmn "github.com/tendermint/tendermint/libs/common"
)

// Apply and return accumulated updates to the bonded validator set. Also,
Expand All @@ -30,8 +29,6 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
maxValidators := k.GetParams(ctx).MaxValidators
totalPower := int64(0)

fmt.Println(cmn.Cyan(fmt.Sprintf("BLOCK #%v ApplyAndReturnValidatorSetUpdates", ctx.BlockHeight())))

// Retrieve the last validator set.
// The persistent set is updated later in this function.
// (see LastValidatorPowerKey).
Expand Down Expand Up @@ -83,24 +80,11 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab

// set validator power on lookup index.
k.SetLastValidatorPower(ctx, operator, sdk.NewDec(newPower))
fmt.Println(
cmn.Cyan(
fmt.Sprintf("SetLastValidatorPower %v pow: %v",
operator, newPower),
),
)
}

// validator still in the validator set, so delete from the copy
delete(last, operatorBytes)

fmt.Println(
cmn.Cyan(
fmt.Sprintf("TOTAL ADD %v pow: %v",
operator, newPower),
),
)

// keep count
count++
totalPower += newPower
Expand All @@ -116,9 +100,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
validator := k.mustGetValidator(ctx, sdk.ValAddress(operator))

// bonded to unbonding
fmt.Println("!!!!")
k.bondedToUnbonding(ctx, validator)
fmt.Println("!!!!2")

// remove validator if it has no more tokens
if validator.Tokens.IsZero() {
Expand All @@ -127,12 +109,6 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab

// delete from the bonded validator index
k.DeleteLastValidatorPower(ctx, sdk.ValAddress(operator))
fmt.Println(
cmn.Cyan(
fmt.Sprintf("SetLastValidatorPower %v pow: 0",
sdk.ValAddress(operator)),
),
)

// update the validator set
updates = append(updates, validator.ABCIValidatorUpdateZero())
Expand All @@ -142,11 +118,6 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
if len(updates) > 0 {
k.SetLastTotalPower(ctx, sdk.NewDec(totalPower))
}
fmt.Println(
cmn.Cyan(
fmt.Sprintf("SetLastTotalPower pow: %v", totalPower),
),
)

return updates
}
Expand Down