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

Refactor delaying of staking updates #32

Merged
merged 6 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
44 changes: 22 additions & 22 deletions x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func TestCalculateRewardsBasic(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -86,8 +86,8 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -153,8 +153,8 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -230,8 +230,8 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand All @@ -258,8 +258,8 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
val = sk.Validator(ctx, valOpAddr1)

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -320,8 +320,8 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -381,8 +381,8 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -453,8 +453,8 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -485,8 +485,8 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {
del2 := sk.Delegation(ctx, sdk.AccAddress(valOpAddr2), valOpAddr1)

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -544,8 +544,8 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {

// end block to bond validator
header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down Expand Up @@ -574,8 +574,8 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
del2 := sk.Delegation(ctx, sdk.AccAddress(valOpAddr2), valOpAddr1)

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// next block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func TestQueries(t *testing.T) {
require.NotNil(t, res)

header := abci.Header{Entropy: abci.BlockEntropy{Round: 1, AeonLength: 3}}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

val := sk.Validator(ctx, valOpAddr1)
rewards := getQueriedDelegationRewards(t, ctx, cdc, querier, sdk.AccAddress(valOpAddr1), valOpAddr1)
Expand Down
8 changes: 4 additions & 4 deletions x/evidence/internal/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign() {

// execute end-blocker and verify validator attributes
header := abci.Header{Entropy: testBlockEntropy()}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &suite.app.StakingKeeper)
staking.EndBlocker(ctx, &suite.app.StakingKeeper)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, suite.app.StakingKeeper)
staking.EndBlocker(ctx, suite.app.StakingKeeper)
suite.Equal(
suite.app.BankKeeper.GetCoins(ctx, sdk.AccAddress(operatorAddr)),
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(amt))),
Expand Down Expand Up @@ -103,8 +103,8 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign_TooOld() {

// execute end-blocker and verify validator attributes
header := abci.Header{Entropy: testBlockEntropy()}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &suite.app.StakingKeeper)
staking.EndBlocker(ctx, &suite.app.StakingKeeper)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, suite.app.StakingKeeper)
staking.EndBlocker(ctx, suite.app.StakingKeeper)
suite.Equal(
suite.app.BankKeeper.GetCoins(ctx, sdk.AccAddress(operatorAddr)),
sdk.NewCoins(sdk.NewCoin(stakingParams.BondDenom, initAmt.Sub(amt))),
Expand Down
4 changes: 2 additions & 2 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func TestProposalPassedEndblocker(t *testing.T) {
valAddr := sdk.ValAddress(input.addrs[0])

createValidators(t, stakingHandler, ctx, []sdk.ValAddress{valAddr}, []int64{10})
staking.EndBlocker(ctx, &input.sk)
staking.EndBlocker(ctx, input.sk)

macc := input.keeper.GetGovernanceAccount(ctx)
require.NotNil(t, macc)
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {
valAddr := sdk.ValAddress(input.addrs[0])

createValidators(t, stakingHandler, ctx, []sdk.ValAddress{valAddr}, []int64{10})
staking.EndBlocker(ctx, &input.sk)
staking.EndBlocker(ctx, input.sk)

// Create a proposal where the handler will pass for the test proposal
// because the value of contextKeyBadProposal is true.
Expand Down
10 changes: 5 additions & 5 deletions x/gov/keeper/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func TestTallyDelgatorOverride(t *testing.T) {
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val1, true)
require.NoError(t, err)

staking.EndBlocker(ctx, &sk)
staking.EndBlocker(ctx, sk)

tp := TestProposal
proposal, err := keeper.SubmitProposal(ctx, tp)
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestTallyDelgatorInherit(t *testing.T) {
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
require.NoError(t, err)

staking.EndBlocker(ctx, &sk)
staking.EndBlocker(ctx, sk)

tp := TestProposal
proposal, err := keeper.SubmitProposal(ctx, tp)
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val2, true)
require.NoError(t, err)

staking.EndBlocker(ctx, &sk)
staking.EndBlocker(ctx, sk)

tp := TestProposal
proposal, err := keeper.SubmitProposal(ctx, tp)
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
require.NoError(t, err)

staking.EndBlocker(ctx, &sk)
staking.EndBlocker(ctx, sk)

tp := TestProposal
proposal, err := keeper.SubmitProposal(ctx, tp)
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestTallyJailedValidator(t *testing.T) {
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
require.NoError(t, err)

staking.EndBlocker(ctx, &sk)
staking.EndBlocker(ctx, sk)

sk.Jail(ctx, sdk.ConsAddress(val2.ConsPubKey.Address()))

Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ func createValidators(ctx sdk.Context, sk staking.Keeper, powers []int64) {
_, _ = sk.Delegate(ctx, valAccAddr3, sdk.TokensFromConsensusPower(powers[2]), sdk.Unbonded, val3, true)

header := abci.Header{Entropy: testBlockEntropy()}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)
}

func testBlockEntropy() abci.BlockEntropy {
Expand Down
8 changes: 4 additions & 4 deletions x/slashing/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestBeginBlocker(t *testing.T) {
require.NotNil(t, res)

header := abci.Header{Entropy: testBlockEntropy()}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)
require.Equal(
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
sdk.NewCoins(sdk.NewCoin(sk.GetParams(ctx).BondDenom, slashingkeeper.InitTokens.Sub(amt))),
Expand Down Expand Up @@ -87,8 +87,8 @@ func TestBeginBlocker(t *testing.T) {
}

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// validator should be jailed
validator, found := sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk))
Expand Down
8 changes: 4 additions & 4 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func getMockApp(t *testing.T) (*mock.App, staking.Keeper, Keeper) {
mapp.Router().AddRoute(staking.RouterKey, staking.NewHandler(stakingKeeper))
mapp.Router().AddRoute(RouterKey, NewHandler(keeper))

mapp.SetBeginBlocker(getBeginBlocker(&stakingKeeper))
mapp.SetEndBlocker(getEndBlocker(&stakingKeeper))
mapp.SetBeginBlocker(getBeginBlocker(stakingKeeper))
mapp.SetEndBlocker(getEndBlocker(stakingKeeper))
mapp.SetInitChainer(getInitChainer(mapp, stakingKeeper, mapp.AccountKeeper, supplyKeeper,
[]supplyexported.ModuleAccountI{feeCollector, notBondedPool, bondPool}))

Expand All @@ -71,15 +71,15 @@ func getMockApp(t *testing.T) (*mock.App, staking.Keeper, Keeper) {
}

// staking endblocker
func getBeginBlocker(keeper *staking.Keeper) sdk.BeginBlocker {
func getBeginBlocker(keeper staking.Keeper) sdk.BeginBlocker {
return func(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
staking.BeginBlocker(ctx, req, keeper)
return abci.ResponseBeginBlock{}
}
}

// staking endblocker
func getEndBlocker(keeper *staking.Keeper) sdk.EndBlocker {
func getEndBlocker(keeper staking.Keeper) sdk.EndBlocker {
return func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
validatorUpdates, _ := staking.EndBlocker(ctx, keeper)
return abci.ResponseEndBlock{
Expand Down
32 changes: 16 additions & 16 deletions x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestCannotUnjailUnlessJailed(t *testing.T) {
require.NotNil(t, res)

header := abci.Header{Entropy: testBlockEntropy()}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

require.Equal(
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, res)

staking.EndBlocker(ctx, &sk)
staking.EndBlocker(ctx, sk)

require.Equal(
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestJailedValidatorDelegations(t *testing.T) {
require.NotNil(t, res)

// end block
staking.EndBlocker(ctx, &stakingKeeper)
staking.EndBlocker(ctx, stakingKeeper)

// set dummy signing info
newInfo := NewValidatorSigningInfo(consAddr, 0, 0, time.Unix(0, 0), false, 0)
Expand Down Expand Up @@ -169,8 +169,8 @@ func TestHandleAbsentValidator(t *testing.T) {
require.NotNil(t, res)

header := abci.Header{Entropy: testBlockEntropy()}
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

require.Equal(
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
Expand Down Expand Up @@ -223,8 +223,8 @@ func TestHandleAbsentValidator(t *testing.T) {
require.Equal(t, int64(0), info.MissedBlocksCounter)

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// validator should have been jailed
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
Expand All @@ -245,8 +245,8 @@ func TestHandleAbsentValidator(t *testing.T) {
require.Equal(t, int64(1), info.MissedBlocksCounter)

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// validator should not have been slashed any more, since it was already jailed
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
Expand All @@ -264,8 +264,8 @@ func TestHandleAbsentValidator(t *testing.T) {
require.NotNil(t, res)

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// validator should be rebonded now
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
Expand Down Expand Up @@ -297,8 +297,8 @@ func TestHandleAbsentValidator(t *testing.T) {
}

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

// validator should be jailed again after 500 unsigned blocks
nextHeight = height + keeper.MinSignedPerWindow(ctx) + 1
Expand All @@ -308,8 +308,8 @@ func TestHandleAbsentValidator(t *testing.T) {
}

// end block
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, &sk)
staking.EndBlocker(ctx, &sk)
staking.BeginBlocker(ctx, abci.RequestBeginBlock{Header: header}, sk)
staking.EndBlocker(ctx, sk)

validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
require.Equal(t, sdk.Unbonding, validator.GetStatus())
Expand Down
Loading