Skip to content

Commit

Permalink
fix: fixed missing coin denomination in msg server logs (backport cos…
Browse files Browse the repository at this point in the history
…mos#9786) (cosmos#9844)

* fix: fixed missing coin denomination in msg server logs (cosmos#9786)

<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

Closes: [cosmos#9785](cosmos#9785)

This PR modifies _x/staking/keeper/msg_server.go_ file and fixes coin denomination issues in the emitted events.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [x] reviewed state machine logic
- [x] reviewed API design and naming
- [x] reviewed documentation is accurate
- [x] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 18eea3a)

# Conflicts:
#	CHANGELOG.md

* Fix conflicts

* move to new section

Co-authored-by: Slav Keremidchiev <skeremidch@gmail.com>
Co-authored-by: Amaury M <1293565+amaurym@users.noreply.github.com>
  • Loading branch information
3 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 98207bc commit 0f538c9
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [\#9793](https://github.com/cosmos/cosmos-sdk/pull/9793) Fixed ECDSA/secp256r1 transaction malleability.

### Client-Breaking Changes

* [\#9785](https://github.com/cosmos/cosmos-sdk/issues/9785) Missing coin denomination in logs

### CLI Breaking Changes

* [\#9827](https://github.com/cosmos/cosmos-sdk/pull/9827) Ensure input parity of validator public key input between `tx staking create-validator` and `gentx`.
Expand Down
121 changes: 85 additions & 36 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,18 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali
return nil, err
}

if err := k.EventService.EventManager(ctx).EmitKV(
types.EventTypeCreateValidator,
event.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
event.NewAttribute(sdk.AttributeKeyAmount, msg.Value.String()),
); err != nil {
return nil, err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeCreateValidator,
sdk.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Value.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.DelegatorAddress),
),
})

return &types.MsgCreateValidatorResponse{}, nil
}
Expand Down Expand Up @@ -299,15 +304,30 @@ func (k msgServer) Delegate(ctx context.Context, msg *types.MsgDelegate) (*types
return nil, err
}

if err := k.EventService.EventManager(ctx).EmitKV(
types.EventTypeDelegate,
event.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
event.NewAttribute(types.AttributeKeyDelegator, msg.DelegatorAddress),
event.NewAttribute(sdk.AttributeKeyAmount, msg.Amount.String()),
event.NewAttribute(types.AttributeKeyNewShares, newShares.String()),
); err != nil {
return nil, err
}
if msg.Amount.Amount.IsInt64() {
defer func() {
telemetry.IncrCounter(1, types.ModuleName, "delegate")
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(
types.EventTypeDelegate,
sdk.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Amount.String()),
sdk.NewAttribute(types.AttributeKeyNewShares, newShares.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.DelegatorAddress),
),
})

return &types.MsgDelegateResponse{}, nil
}
Expand Down Expand Up @@ -361,15 +381,31 @@ func (k msgServer) BeginRedelegate(ctx context.Context, msg *types.MsgBeginRedel
return nil, err
}

if err := k.EventService.EventManager(ctx).EmitKV(
types.EventTypeRedelegate,
event.NewAttribute(types.AttributeKeySrcValidator, msg.ValidatorSrcAddress),
event.NewAttribute(types.AttributeKeyDstValidator, msg.ValidatorDstAddress),
event.NewAttribute(sdk.AttributeKeyAmount, msg.Amount.String()),
event.NewAttribute(types.AttributeKeyCompletionTime, completionTime.Format(time.RFC3339)),
); err != nil {
return nil, err
}
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(
types.EventTypeRedelegate,
sdk.NewAttribute(types.AttributeKeySrcValidator, msg.ValidatorSrcAddress),
sdk.NewAttribute(types.AttributeKeyDstValidator, msg.ValidatorDstAddress),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Amount.String()),
sdk.NewAttribute(types.AttributeKeyCompletionTime, completionTime.Format(time.RFC3339)),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.DelegatorAddress),
),
})

return &types.MsgBeginRedelegateResponse{
CompletionTime: completionTime,
Expand Down Expand Up @@ -418,17 +454,30 @@ func (k msgServer) Undelegate(ctx context.Context, msg *types.MsgUndelegate) (*t
return nil, err
}

undelegatedCoin := sdk.NewCoin(msg.Amount.Denom, undelegatedAmt)

if err := k.EventService.EventManager(ctx).EmitKV(
types.EventTypeUnbond,
event.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
event.NewAttribute(types.AttributeKeyDelegator, msg.DelegatorAddress),
event.NewAttribute(sdk.AttributeKeyAmount, undelegatedCoin.String()),
event.NewAttribute(types.AttributeKeyCompletionTime, completionTime.Format(time.RFC3339)),
); err != nil {
return nil, err
}
if msg.Amount.Amount.IsInt64() {
defer func() {
telemetry.IncrCounter(1, types.ModuleName, "undelegate")
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(
types.EventTypeUnbond,
sdk.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Amount.String()),
sdk.NewAttribute(types.AttributeKeyCompletionTime, completionTime.Format(time.RFC3339)),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.DelegatorAddress),
),
})

return &types.MsgUndelegateResponse{
CompletionTime: completionTime,
Expand Down

0 comments on commit 0f538c9

Please sign in to comment.