WIP looking for bug...
This commit is contained in:
parent
1630c0f0f3
commit
fa3730a5d2
|
@ -341,8 +341,9 @@ func (h Hooks) OnValidatorModified(ctx sdk.Context, addr sdk.ValAddress) {
|
||||||
func (h Hooks) OnValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) {
|
func (h Hooks) OnValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) {
|
||||||
h.dh.OnValidatorRemoved(ctx, addr)
|
h.dh.OnValidatorRemoved(ctx, addr)
|
||||||
}
|
}
|
||||||
func (h Hooks) OnValidatorBonded(ctx sdk.Context, addr sdk.ConsAddress) {
|
func (h Hooks) OnValidatorBonded(ctx sdk.Context, addr sdk.ConsAddress, operator sdk.ValAddress) {
|
||||||
h.sh.OnValidatorBonded(ctx, addr)
|
h.dh.OnValidatorBonded(ctx, addr, operator)
|
||||||
|
h.sh.OnValidatorBonded(ctx, addr, operator)
|
||||||
}
|
}
|
||||||
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, addr sdk.ConsAddress, operator sdk.ValAddress) {
|
func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, addr sdk.ConsAddress, operator sdk.ValAddress) {
|
||||||
h.dh.OnValidatorBeginUnbonding(ctx, addr, operator)
|
h.dh.OnValidatorBeginUnbonding(ctx, addr, operator)
|
||||||
|
|
|
@ -66,7 +66,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||||
var delegations []stake.Delegation
|
var delegations []stake.Delegation
|
||||||
|
|
||||||
// XXX Try different numbers of initially bonded validators
|
// XXX Try different numbers of initially bonded validators
|
||||||
numInitiallyBonded := int64(50)
|
numInitiallyBonded := int64(5)
|
||||||
valAddrs := make([]sdk.ValAddress, numInitiallyBonded)
|
valAddrs := make([]sdk.ValAddress, numInitiallyBonded)
|
||||||
for i := 0; i < int(numInitiallyBonded); i++ {
|
for i := 0; i < int(numInitiallyBonded); i++ {
|
||||||
valAddr := sdk.ValAddress(accs[i].Address)
|
valAddr := sdk.ValAddress(accs[i].Address)
|
||||||
|
|
|
@ -115,7 +115,7 @@ type StakingHooks interface {
|
||||||
OnValidatorModified(ctx Context, address ValAddress) // Must be called when a validator's state changes
|
OnValidatorModified(ctx Context, address ValAddress) // Must be called when a validator's state changes
|
||||||
OnValidatorRemoved(ctx Context, address ValAddress) // Must be called when a validator is deleted
|
OnValidatorRemoved(ctx Context, address ValAddress) // Must be called when a validator is deleted
|
||||||
|
|
||||||
OnValidatorBonded(ctx Context, address ConsAddress) // Must be called when a validator is bonded
|
OnValidatorBonded(ctx Context, address ConsAddress, operator ValAddress) // Must be called when a validator is bonded
|
||||||
OnValidatorBeginUnbonding(ctx Context, address ConsAddress, operator ValAddress) // Must be called when a validator begins unbonding
|
OnValidatorBeginUnbonding(ctx Context, address ConsAddress, operator ValAddress) // Must be called when a validator begins unbonding
|
||||||
|
|
||||||
OnDelegationCreated(ctx Context, delAddr AccAddress, valAddr ValAddress) // Must be called when a delegation is created
|
OnDelegationCreated(ctx Context, delAddr AccAddress, valAddr ValAddress) // Must be called when a delegation is created
|
||||||
|
|
|
@ -105,5 +105,6 @@ func (h Hooks) OnValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, add
|
||||||
h.k.onValidatorModified(ctx, addr)
|
h.k.onValidatorModified(ctx, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint - unused hooks for interface
|
func (h Hooks) OnValidatorBonded(ctx sdk.Context, _ sdk.ConsAddress, addr sdk.ValAddress) {
|
||||||
func (h Hooks) OnValidatorBonded(ctx sdk.Context, addr sdk.ConsAddress) {}
|
h.k.onValidatorModified(ctx, addr)
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (k Keeper) onValidatorBonded(ctx sdk.Context, address sdk.ConsAddress) {
|
func (k Keeper) onValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) {
|
||||||
// Update the signing info start height or create a new signing info
|
// Update the signing info start height or create a new signing info
|
||||||
_, found := k.getValidatorSigningInfo(ctx, address)
|
_, found := k.getValidatorSigningInfo(ctx, address)
|
||||||
if !found {
|
if !found {
|
||||||
|
@ -51,8 +51,8 @@ func (k Keeper) Hooks() Hooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements sdk.ValidatorHooks
|
// Implements sdk.ValidatorHooks
|
||||||
func (h Hooks) OnValidatorBonded(ctx sdk.Context, address sdk.ConsAddress) {
|
func (h Hooks) OnValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, operator sdk.ValAddress) {
|
||||||
h.k.onValidatorBonded(ctx, address)
|
h.k.onValidatorBonded(ctx, address, operator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements sdk.ValidatorHooks
|
// Implements sdk.ValidatorHooks
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
func TestHookOnValidatorBonded(t *testing.T) {
|
func TestHookOnValidatorBonded(t *testing.T) {
|
||||||
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
||||||
addr := sdk.ConsAddress(addrs[0])
|
addr := sdk.ConsAddress(addrs[0])
|
||||||
keeper.onValidatorBonded(ctx, addr)
|
keeper.onValidatorBonded(ctx, addr, nil)
|
||||||
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
||||||
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), 0, sdk.ZeroDec()}, period)
|
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), 0, sdk.ZeroDec()}, period)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func TestHookOnValidatorBonded(t *testing.T) {
|
||||||
func TestHookOnValidatorBeginUnbonding(t *testing.T) {
|
func TestHookOnValidatorBeginUnbonding(t *testing.T) {
|
||||||
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
ctx, _, _, _, keeper := createTestInput(t, DefaultParams())
|
||||||
addr := sdk.ConsAddress(addrs[0])
|
addr := sdk.ConsAddress(addrs[0])
|
||||||
keeper.onValidatorBonded(ctx, addr)
|
keeper.onValidatorBonded(ctx, addr, nil)
|
||||||
keeper.onValidatorBeginUnbonding(ctx, addr, addrs[0])
|
keeper.onValidatorBeginUnbonding(ctx, addr, addrs[0])
|
||||||
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
||||||
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), ctx.BlockHeight(), sdk.ZeroDec()}, period)
|
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), ctx.BlockHeight(), sdk.ZeroDec()}, period)
|
||||||
|
|
|
@ -23,9 +23,9 @@ func (k Keeper) OnValidatorRemoved(ctx sdk.Context, address sdk.ValAddress) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) OnValidatorBonded(ctx sdk.Context, address sdk.ConsAddress) {
|
func (k Keeper) OnValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, operator sdk.ValAddress) {
|
||||||
if k.hooks != nil {
|
if k.hooks != nil {
|
||||||
k.hooks.OnValidatorBonded(ctx, address)
|
k.hooks.OnValidatorBonded(ctx, address, operator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,9 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
|
||||||
validator := k.mustGetValidator(ctx, sdk.ValAddress(operator))
|
validator := k.mustGetValidator(ctx, sdk.ValAddress(operator))
|
||||||
|
|
||||||
// bonded to unbonding
|
// bonded to unbonding
|
||||||
|
fmt.Println("!!!!")
|
||||||
k.bondedToUnbonding(ctx, validator)
|
k.bondedToUnbonding(ctx, validator)
|
||||||
|
fmt.Println("!!!!2")
|
||||||
|
|
||||||
// remove validator if it has no more tokens
|
// remove validator if it has no more tokens
|
||||||
if validator.Tokens.IsZero() {
|
if validator.Tokens.IsZero() {
|
||||||
|
@ -224,7 +226,7 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.
|
||||||
|
|
||||||
// call the bond hook if present
|
// call the bond hook if present
|
||||||
if k.hooks != nil {
|
if k.hooks != nil {
|
||||||
k.hooks.OnValidatorBonded(ctx, validator.ConsAddress())
|
k.hooks.OnValidatorBonded(ctx, validator.ConsAddress(), validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return validator
|
return validator
|
||||||
|
|
Loading…
Reference in New Issue