-
Notifications
You must be signed in to change notification settings - Fork 657
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
Add WriteUpgradeConfirm function. #4303
Changes from all commits
88d2e86
97c38a8
79f31b4
d38ddb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,6 +337,28 @@ func emitChannelUpgradeAckEvent(ctx sdk.Context, portID string, channelID string | |
}) | ||
} | ||
|
||
// emitChannelUpgradeConfirmEvent emits a channel upgrade confirm event | ||
func emitChannelUpgradeConfirmEvent(ctx sdk.Context, portID, channelID string, currentChannel types.Channel) { | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeChannelUpgradeConfirm, | ||
sdk.NewAttribute(types.AttributeKeyPortID, portID), | ||
sdk.NewAttribute(types.AttributeKeyChannelID, channelID), | ||
sdk.NewAttribute(types.AttributeKeyChannelState, currentChannel.State.String()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We emit the channel state here because the relayer will need it to execute There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that was idea, though its becoming increasingly unclear to me if relayers are actually using events (I remember rly didnt?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are using events to parse the data out as "response data", both hermes and rly as far as I know |
||
sdk.NewAttribute(types.AttributeCounterpartyPortID, currentChannel.Counterparty.PortId), | ||
sdk.NewAttribute(types.AttributeCounterpartyChannelID, currentChannel.Counterparty.ChannelId), | ||
sdk.NewAttribute(types.AttributeKeyUpgradeConnectionHops, currentChannel.ConnectionHops[0]), | ||
sdk.NewAttribute(types.AttributeKeyUpgradeVersion, currentChannel.Version), | ||
sdk.NewAttribute(types.AttributeKeyUpgradeOrdering, currentChannel.Ordering.String()), | ||
sdk.NewAttribute(types.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", currentChannel.UpgradeSequence)), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
), | ||
}) | ||
} | ||
|
||
// emitChannelUpgradeOpenEvent emits a channel upgrade open event | ||
func emitChannelUpgradeOpenEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel) { | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,6 +351,31 @@ func (k Keeper) WriteUpgradeAckChannel(ctx sdk.Context, portID, channelID string | |
emitChannelUpgradeAckEvent(ctx, portID, channelID, channel, upgrade) | ||
} | ||
|
||
// WriteUpgradeConfirmChannel writes a channel which has successfully passed the ChanUpgradeConfirm handshake step. | ||
// If the channel has no in-flight packets, its state is updated to indicate that flushing has completed. Otherwise, the counterparty upgrade is set | ||
// and the channel state is left unchanged. | ||
// An event is emitted for the handshake step. | ||
func (k Keeper) WriteUpgradeConfirmChannel(ctx sdk.Context, portID, channelID string, counterpartyUpgrade types.Upgrade) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we write some short and sweet godoc prose for this beautiful function? ✍️ |
||
defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-confirm") | ||
|
||
channel, found := k.GetChannel(ctx, portID, channelID) | ||
if !found { | ||
panic(fmt.Sprintf("could not find existing channel when updating channel state in successful ChanUpgradeConfirm step, channelID: %s, portID: %s", channelID, portID)) | ||
} | ||
|
||
if !k.HasInflightPackets(ctx, portID, channelID) { | ||
previousState := channel.State | ||
channel.State = types.STATE_FLUSHCOMPLETE | ||
k.SetChannel(ctx, portID, channelID, channel) | ||
|
||
k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", previousState, "new-state", channel.State) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be moved outside if? Added here considering we only update channel state in this case. |
||
} else { | ||
k.SetCounterpartyUpgrade(ctx, portID, channelID, counterpartyUpgrade) | ||
crodriguezvega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
emitChannelUpgradeConfirmEvent(ctx, portID, channelID, channel) | ||
} | ||
|
||
// ChanUpgradeOpen is called by a module to complete the channel upgrade handshake and move the channel back to an OPEN state. | ||
// This method should only be called after both channels have flushed any in-flight packets. | ||
// This method should only be called directly by the core IBC message server. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe we generally emit counterparty info in events, not 100% certain tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like port ID and channel ID? I think we do, so should be fine.