diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index 3f60138224..24a5b94491 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -139,7 +139,17 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress panic("InitializeTestLCD must use at least one validator") } - for i := 1; i < nValidators; i++ { + // add the priv validator (actual node) to genesis validators + genDoc.Validators = append(genDoc.Validators, + tmtypes.GenesisValidator{ + PubKey: privVal.PubKey, + Power: 1, + Name: "val", + }, + ) + + // then add some randoms + for i := 2; i < nValidators; i++ { genDoc.Validators = append(genDoc.Validators, tmtypes.GenesisValidator{ PubKey: ed25519.GenPrivKey().PubKey(), diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 749588c437..9c07f895ed 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -98,7 +98,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams) app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, app.RegisterCodespace(stake.DefaultCodespace)) - app.distrKeeper = distr.NewKeeper(app.cdc, app.keyDistr, app.tkeyStake, + app.distrKeeper = distr.NewKeeper(app.cdc, app.keyDistr, app.tkeyDistr, app.paramsKeeper.Setter(), app.bankKeeper, app.stakeKeeper, app.feeCollectionKeeper, app.RegisterCodespace(stake.DefaultCodespace)) app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, @@ -168,7 +168,7 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper) // distribute rewards - //distr.EndBlocker(ctx, app.distrKeeper) + distr.EndBlocker(ctx, app.distrKeeper) // Add these new validators to the addr -> pubkey map. app.slashingKeeper.AddValidators(ctx, validatorUpdates) diff --git a/x/distribution/abci_app.go b/x/distribution/abci_app.go index 648d70a5dc..57c10d013b 100644 --- a/x/distribution/abci_app.go +++ b/x/distribution/abci_app.go @@ -15,5 +15,8 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) // allocate fees func EndBlocker(ctx sdk.Context, k keeper.Keeper) { + if ctx.BlockHeight() < 2 { + return + } k.AllocateFees(ctx) } diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 03742fdac9..4a2d820036 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -9,19 +9,17 @@ import ( // Allocate fees handles distribution of the collected fees func (k Keeper) AllocateFees(ctx sdk.Context) { - fmt.Println("wackydebugoutput AllocateFees 0") + ctx.Logger().With("module", "x/distribution").Error(fmt.Sprintf("allocation height: %v", ctx.BlockHeight())) // get the proposer of this block proposerConsAddr := k.GetProposerConsAddr(ctx) proposerValidator := k.stakeKeeper.ValidatorByConsAddr(ctx, proposerConsAddr) proposerDist := k.GetValidatorDistInfo(ctx, proposerValidator.GetOperator()) - fmt.Println("wackydebugoutput AllocateFees 1") // get the fees which have been getting collected through all the // transactions in the block feesCollected := k.feeCollectionKeeper.GetCollectedFees(ctx) feesCollectedDec := types.NewDecCoins(feesCollected) - fmt.Println("wackydebugoutput AllocateFees 2") // allocated rewards to proposer bondedTokens := k.stakeKeeper.TotalPower(ctx) @@ -29,30 +27,25 @@ func (k Keeper) AllocateFees(ctx sdk.Context) { proposerMultiplier := sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(4, 2).Mul( sumPowerPrecommitValidators).Quo(bondedTokens)) proposerReward := feesCollectedDec.Mul(proposerMultiplier) - fmt.Println("wackydebugoutput AllocateFees 3") // apply commission commission := proposerReward.Mul(proposerValidator.GetCommission()) remaining := proposerReward.Mul(sdk.OneDec().Sub(proposerValidator.GetCommission())) proposerDist.PoolCommission = proposerDist.PoolCommission.Plus(commission) proposerDist.Pool = proposerDist.Pool.Plus(remaining) - fmt.Println("wackydebugoutput AllocateFees 4") // allocate community funding communityTax := k.GetCommunityTax(ctx) communityFunding := feesCollectedDec.Mul(communityTax) feePool := k.GetFeePool(ctx) feePool.CommunityPool = feePool.CommunityPool.Plus(communityFunding) - fmt.Println("wackydebugoutput AllocateFees 5") // set the global pool within the distribution module poolReceived := feesCollectedDec.Mul(sdk.OneDec().Sub(proposerMultiplier).Sub(communityTax)) feePool.Pool = feePool.Pool.Plus(poolReceived) - fmt.Println("wackydebugoutput AllocateFees 0") k.SetValidatorDistInfo(ctx, proposerDist) k.SetFeePool(ctx, feePool) - fmt.Println("wackydebugoutput AllocateFees 6") // clear the now distributed fees k.feeCollectionKeeper.ClearCollectedFees(ctx) diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 34caa5c1a9..6aa0c4ee57 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -79,7 +79,10 @@ func (k Keeper) WithdrawDelegationReward(ctx sdk.Context, delegatorAddr sdk.AccA k.SetFeePool(ctx, feePool) withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, delegatorAddr) - k.bankKeeper.AddCoins(ctx, withdrawAddr, withdraw.TruncateDecimal()) + _, _, err := k.bankKeeper.AddCoins(ctx, withdrawAddr, withdraw.TruncateDecimal()) + if err != nil { + panic(err) + } } //___________________________________________________________________________________________ @@ -89,7 +92,10 @@ func (k Keeper) WithdrawDelegationRewardsAll(ctx sdk.Context, delegatorAddr sdk. height := ctx.BlockHeight() withdraw := k.GetDelegatorRewardsAll(ctx, delegatorAddr, height) withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, delegatorAddr) - k.bankKeeper.AddCoins(ctx, withdrawAddr, withdraw.TruncateDecimal()) + _, _, err := k.bankKeeper.AddCoins(ctx, withdrawAddr, withdraw.TruncateDecimal()) + if err != nil { + panic(err) + } } // return all rewards for all delegations of a delegator diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 0803d2493a..e49793ddcd 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -65,9 +65,9 @@ func (k Keeper) SetFeePool(ctx sdk.Context, feePool types.FeePool) { // set the proposer public key for this block func (k Keeper) GetProposerConsAddr(ctx sdk.Context) (consAddr sdk.ConsAddress) { - store := ctx.KVStore(k.storeKey) + tstore := ctx.KVStore(k.storeTKey) - b := store.Get(ProposerKey) + b := tstore.Get(ProposerKey) if b == nil { panic("Stored fee pool should not have been nil") } @@ -78,9 +78,9 @@ func (k Keeper) GetProposerConsAddr(ctx sdk.Context) (consAddr sdk.ConsAddress) // get the proposer public key for this block func (k Keeper) SetProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) { - store := ctx.KVStore(k.storeKey) + tstore := ctx.KVStore(k.storeTKey) b := k.cdc.MustMarshalBinary(consAddr) - store.Set(ProposerKey, b) + tstore.Set(ProposerKey, b) } //______________________________________________________________________ diff --git a/x/distribution/keeper/key.go b/x/distribution/keeper/key.go index 6162baf6dc..771343f017 100644 --- a/x/distribution/keeper/key.go +++ b/x/distribution/keeper/key.go @@ -6,10 +6,10 @@ import ( // keys/key-prefixes var ( - FeePoolKey = []byte{0x01} // key for global distribution state - ValidatorDistInfoKey = []byte{0x02} // prefix for each key to a validator distribution - DelegatorDistInfoKey = []byte{0x03} // prefix for each key to a delegation distribution - DelegatorWithdrawInfoKey = []byte{0x04} // prefix for each key to a delegator withdraw info + FeePoolKey = []byte{0x00} // key for global distribution state + ValidatorDistInfoKey = []byte{0x01} // prefix for each key to a validator distribution + DelegatorDistInfoKey = []byte{0x02} // prefix for each key to a delegation distribution + DelegatorWithdrawInfoKey = []byte{0x03} // prefix for each key to a delegator withdraw info // transient ProposerKey = []byte{0x00} // key for storing the proposer operator address diff --git a/x/distribution/keeper/validator.go b/x/distribution/keeper/validator.go index 45ff70fd96..baeb6ab311 100644 --- a/x/distribution/keeper/validator.go +++ b/x/distribution/keeper/validator.go @@ -53,5 +53,8 @@ func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.Va k.SetFeePool(ctx, feePool) withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, accAddr) - k.bankKeeper.AddCoins(ctx, withdrawAddr, withdraw.TruncateDecimal()) + _, _, err := k.bankKeeper.AddCoins(ctx, withdrawAddr, withdraw.TruncateDecimal()) + if err != nil { + panic(err) + } }