fix build issues && telemetry.SetGaugeWithLabels int64 range validation
This commit is contained in:
parent
4582dcd08f
commit
67b3f9071c
|
@ -50,11 +50,13 @@ func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSe
|
|||
|
||||
defer func() {
|
||||
for _, a := range msg.Amount {
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", "send"},
|
||||
float32(a.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", a.Denom)},
|
||||
)
|
||||
if a.Amount.IsInt64() {
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", "send"},
|
||||
float32(a.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", a.Denom)},
|
||||
)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) {
|
|||
|
||||
// create validator with 50% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(sdk.ValAddress(addrs[0]), valConsPk1, 100, true)
|
||||
tstaking.CreateValidator(sdk.ValAddress(addrs[0]), valConsPk1, sdk.NewInt(100), true)
|
||||
val := app.StakingKeeper.Validator(ctx, valAddrs[0])
|
||||
|
||||
// allocate tokens
|
||||
|
@ -53,11 +53,11 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
|
|||
|
||||
// create validator with 50% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
|
||||
|
||||
// create second validator with 0% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[1], valConsPk2, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), true)
|
||||
|
||||
abciValA := abci.Validator{
|
||||
Address: valConsPk1.Address(),
|
||||
|
@ -123,15 +123,15 @@ func TestAllocateTokensTruncation(t *testing.T) {
|
|||
|
||||
// create validator with 10% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, 110, true)
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(110), true)
|
||||
|
||||
// create second validator with 10% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[1], valConsPk2, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), true)
|
||||
|
||||
// create third validator with 10% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[2], valConsPk3, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[2], valConsPk3, sdk.NewInt(100), true)
|
||||
|
||||
abciValA := abci.Validator{
|
||||
Address: valConsPk1.Address(),
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestCalculateRewardsBasic(t *testing.T) {
|
|||
|
||||
// create validator with 50% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
|
||||
|
||||
// end block to bond validator and start new block
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -215,7 +215,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
|
|||
|
||||
// create validator with 50% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
|
||||
|
||||
// end block to bond validator
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -234,7 +234,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
|
|||
|
||||
// second delegation
|
||||
tstaking.Ctx = ctx
|
||||
tstaking.Delegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], 100)
|
||||
tstaking.Delegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], sdk.NewInt(100))
|
||||
del2 := app.StakingKeeper.Delegation(ctx, sdk.AccAddress(valAddrs[1]), valAddrs[0])
|
||||
|
||||
// fetch updated validator
|
||||
|
@ -500,7 +500,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
|
|||
|
||||
// create validator with 50% commission
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
|
||||
|
||||
// end block to bond validator
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -519,7 +519,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
|
|||
require.Equal(t, uint64(2), app.DistrKeeper.GetValidatorHistoricalReferenceCount(ctx))
|
||||
|
||||
// second delegation
|
||||
tstaking.Delegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], 100)
|
||||
tstaking.Delegate(sdk.AccAddress(valAddrs[1]), valAddrs[0], sdk.NewInt(100))
|
||||
|
||||
// historical count should be 3 (second delegation init)
|
||||
require.Equal(t, uint64(3), app.DistrKeeper.GetValidatorHistoricalReferenceCount(ctx))
|
||||
|
|
|
@ -343,7 +343,7 @@ func (suite *KeeperTestSuite) TestGRPCDelegationRewards() {
|
|||
|
||||
tstaking := teststaking.NewHelper(suite.T(), ctx, app.StakingKeeper)
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, 100, true)
|
||||
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
|
||||
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
|
||||
|
|
|
@ -66,11 +66,13 @@ func (k msgServer) WithdrawDelegatorReward(goCtx context.Context, msg *types.Msg
|
|||
|
||||
defer func() {
|
||||
for _, a := range amount {
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", "withdraw_reward"},
|
||||
float32(a.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", a.Denom)},
|
||||
)
|
||||
if a.Amount.IsInt64() {
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", "withdraw_reward"},
|
||||
float32(a.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", a.Denom)},
|
||||
)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -98,11 +100,13 @@ func (k msgServer) WithdrawValidatorCommission(goCtx context.Context, msg *types
|
|||
|
||||
defer func() {
|
||||
for _, a := range amount {
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", "withdraw_commission"},
|
||||
float32(a.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", a.Denom)},
|
||||
)
|
||||
if a.Amount.IsInt64() {
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", "withdraw_commission"},
|
||||
float32(a.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", a.Denom)},
|
||||
)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ func TestQueries(t *testing.T) {
|
|||
// test delegation rewards query
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
|
||||
tstaking.CreateValidator(valOpAddr1, valConsPk1, 100, true)
|
||||
tstaking.CreateValidator(valOpAddr1, valConsPk1, sdk.NewInt(100), true)
|
||||
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ func TestBeginBlocker(t *testing.T) {
|
|||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
|
||||
// bond the validator
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, pk, 100, true)
|
||||
power := int64(100)
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true)
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
require.Equal(
|
||||
t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)),
|
||||
|
@ -36,7 +37,7 @@ func TestBeginBlocker(t *testing.T) {
|
|||
|
||||
val := abci.Validator{
|
||||
Address: pk.Address(),
|
||||
Power: amt.Int64(),
|
||||
Power: power,
|
||||
}
|
||||
|
||||
// mark the validator as having signed
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) {
|
|||
slh := slashing.NewHandler(app.SlashingKeeper)
|
||||
addr, val := sdk.ValAddress(pks[0].Address()), pks[0]
|
||||
amt := sdk.TokensFromConsensusPower(100)
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt.Int64())
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt)
|
||||
msg.MinSelfDelegation = amt
|
||||
tstaking.Handle(msg, true)
|
||||
|
||||
|
@ -101,7 +101,7 @@ func TestJailedValidatorDelegations(t *testing.T) {
|
|||
|
||||
// delegate tokens to the validator
|
||||
delAddr := sdk.AccAddress(pks[2].Address())
|
||||
tstaking.Delegate(delAddr, valAddr, amt.Int64())
|
||||
tstaking.Delegate(delAddr, valAddr, amt)
|
||||
|
||||
// unbond validator total self-delegations (which should jail the validator)
|
||||
valAcc := sdk.AccAddress(valAddr)
|
||||
|
@ -120,7 +120,7 @@ func TestJailedValidatorDelegations(t *testing.T) {
|
|||
require.Nil(t, res)
|
||||
|
||||
// self-delegate to validator
|
||||
tstaking.Delegate(valAcc, valAddr, amt.Int64())
|
||||
tstaking.Delegate(valAcc, valAddr, amt)
|
||||
|
||||
// verify the validator can now unjail itself
|
||||
res, err = slashing.NewHandler(app.SlashingKeeper)(ctx, types.NewMsgUnjail(valAddr))
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
|||
// create a 6th validator with less power than the cliff validator (won't be bonded)
|
||||
addr, val := valAddrs[5], pks[5]
|
||||
amt := sdk.TokensFromConsensusPower(50)
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt.Int64())
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt)
|
||||
msg.MinSelfDelegation = amt
|
||||
tstaking.Handle(msg, true)
|
||||
|
||||
|
|
|
@ -270,14 +270,16 @@ func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRed
|
|||
return nil, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
telemetry.IncrCounter(1, types.ModuleName, "redelegate")
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", msg.Type()},
|
||||
float32(msg.Amount.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)},
|
||||
)
|
||||
}()
|
||||
if msg.Amount.Amount.IsInt64() {
|
||||
defer func() {
|
||||
telemetry.IncrCounter(1, types.ModuleName, "redelegate")
|
||||
telemetry.SetGaugeWithLabels(
|
||||
[]string{"tx", "msg", msg.Type()},
|
||||
float32(msg.Amount.Amount.Int64()),
|
||||
[]metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)},
|
||||
)
|
||||
}()
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
|
|
Loading…
Reference in New Issue