Skip to content

Commit bb3d1cf

Browse files
mergify[bot]seantkingcrodriguezvega
authored
feat: emitting an event when handling a client upgrade proposal (backport #1570) (#1766)
* feat: emitting an event when handling a client upgrade proposal (#1570) * feat: emitting an event when handling a client upgrade proposal * refactor: only emit event if err is nil * refactor: idiotmatic go: (cherry picked from commit 8422d0c) # Conflicts: # CHANGELOG.md # modules/core/02-client/keeper/events.go * fix conflicts * add new line * remove unused import Co-authored-by: Sean King <seantking@users.noreply.github.com> Co-authored-by: crodriguezvega <carlos@interchain.io>
1 parent a061fab commit bb3d1cf

4 files changed

Lines changed: 42 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4747

4848
### Improvements
4949

50+
* (core/02-client) [\#1570](https://github.com/cosmos/ibc-go/pull/1570) Emitting an event when handling an upgrade client proposal.
5051
* (app/20-transfer) [\#1680](https://github.com/cosmos/ibc-go/pull/1680) Adds migration to correct any malformed trace path information of tokens with denoms that contains slashes. The transfer module consensus version has been bumped to 2.
5152
* (app/20-transfer) [\#1730](https://github.com/cosmos/ibc-go/pull/1730) parse the ics20 denomination provided via a packet using the channel identifier format specified by ibc-go.
5253

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package keeper
2+
3+
import (
4+
"fmt"
5+
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
8+
"github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
9+
)
10+
11+
// EmitUpgradeClientProposalEvent emits an upgrade client proposal event
12+
func EmitUpgradeClientProposalEvent(ctx sdk.Context, title string, height int64) {
13+
ctx.EventManager().EmitEvent(
14+
sdk.NewEvent(
15+
types.EventTypeUpgradeClientProposal,
16+
sdk.NewAttribute(types.AttributeKeyUpgradePlanTitle, title),
17+
sdk.NewAttribute(types.AttributeKeyUpgradePlanHeight, fmt.Sprintf("%d", height)),
18+
),
19+
)
20+
}

modules/core/02-client/keeper/proposal.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,12 @@ func (k Keeper) HandleUpgradeProposal(ctx sdk.Context, p *types.UpgradeProposal)
105105

106106
// sets the new upgraded client in last height committed on this chain is at plan.Height,
107107
// since the chain will panic at plan.Height and new chain will resume at plan.Height
108-
return k.upgradeKeeper.SetUpgradedClient(ctx, p.Plan.Height, bz)
108+
if err = k.upgradeKeeper.SetUpgradedClient(ctx, p.Plan.Height, bz); err != nil {
109+
return err
110+
}
111+
112+
// emitting an event for handling client upgrade proposal
113+
EmitUpgradeClientProposalEvent(ctx, p.Title, p.Plan.Height)
114+
115+
return nil
109116
}

modules/core/02-client/types/events.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ import (
88

99
// IBC client events
1010
const (
11-
AttributeKeyClientID = "client_id"
12-
AttributeKeySubjectClientID = "subject_client_id"
13-
AttributeKeyClientType = "client_type"
14-
AttributeKeyConsensusHeight = "consensus_height"
15-
AttributeKeyHeader = "header"
11+
AttributeKeyClientID = "client_id"
12+
AttributeKeySubjectClientID = "subject_client_id"
13+
AttributeKeyClientType = "client_type"
14+
AttributeKeyConsensusHeight = "consensus_height"
15+
AttributeKeyHeader = "header"
16+
AttributeKeyUpgradePlanTitle = "title"
17+
AttributeKeyUpgradePlanHeight = "height"
1618
)
1719

1820
// IBC client events vars
1921
var (
20-
EventTypeCreateClient = "create_client"
21-
EventTypeUpdateClient = "update_client"
22-
EventTypeUpgradeClient = "upgrade_client"
23-
EventTypeSubmitMisbehaviour = "client_misbehaviour"
24-
EventTypeUpdateClientProposal = "update_client_proposal"
22+
EventTypeCreateClient = "create_client"
23+
EventTypeUpdateClient = "update_client"
24+
EventTypeUpgradeClient = "upgrade_client"
25+
EventTypeSubmitMisbehaviour = "client_misbehaviour"
26+
EventTypeUpdateClientProposal = "update_client_proposal"
27+
EventTypeUpgradeClientProposal = "upgrade_client_proposal"
2528

2629
AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, SubModuleName)
2730
)

0 commit comments

Comments
 (0)