-
Notifications
You must be signed in to change notification settings - Fork 625
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
refactor: WriteAcknowledgement API #882
Changes from 5 commits
95b7e8e
9f44d36
b16f85e
37ba44f
8d5c66d
fea6321
d3b7625
fca9daf
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Migrating from ibc-go v2 to v3 | ||
|
||
This document is intended to highlight significant changes which may require more information than presented in the CHANGELOG. | ||
Any changes that must be done by a user of ibc-go should be documented here. | ||
|
||
There are four sections based on the four potential user groups of this document: | ||
- Chains | ||
- IBC Apps | ||
- Relayers | ||
- IBC Light Clients | ||
|
||
**Note:** ibc-go supports golang semantic versioning and therefore all imports must be updated to bump the version number on major releases. | ||
```go | ||
github.com/cosmos/ibc-go/v2 -> github.com/cosmos/ibc-go/v3 | ||
``` | ||
|
||
No genesis or in-place migrations required when upgrading from v1 or v2 of ibc-go. | ||
|
||
## Chains | ||
|
||
### IS04 - Channel | ||
|
||
The `WriteAcknowledgement` API now takes the `exported.Acknowledgement` type instead of passing in the acknowledgement byte array directly. | ||
This is an API breaking change and as such IBC application developers will have to update any calls to `WriteAcknowledgement`. | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -312,7 +312,7 @@ func (k Keeper) WriteAcknowledgement( | |||||
ctx sdk.Context, | ||||||
chanCap *capabilitytypes.Capability, | ||||||
packet exported.PacketI, | ||||||
acknowledgement []byte, | ||||||
acknowledgement exported.Acknowledgement, | ||||||
) error { | ||||||
channel, found := k.GetChannel(ctx, packet.GetDestPort(), packet.GetDestChannel()) | ||||||
if !found { | ||||||
|
@@ -342,14 +342,15 @@ func (k Keeper) WriteAcknowledgement( | |||||
return types.ErrAcknowledgementExists | ||||||
} | ||||||
|
||||||
if len(acknowledgement) == 0 { | ||||||
damiannolan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
bz := acknowledgement.Acknowledgement() | ||||||
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. You should still check if acknowledgement is nil first or it will panic 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. Good call, thank you |
||||||
if len(bz) == 0 { | ||||||
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.
Suggested change
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. Added the check as a separate if statement. Just my personal preference. |
||||||
return sdkerrors.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") | ||||||
Comment on lines
+349
to
351
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. Just change this check to |
||||||
} | ||||||
|
||||||
// set the acknowledgement so that it can be verified on the other side | ||||||
k.SetPacketAcknowledgement( | ||||||
ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), | ||||||
types.CommitAcknowledgement(acknowledgement), | ||||||
types.CommitAcknowledgement(bz), | ||||||
) | ||||||
|
||||||
// log that a packet acknowledgement has been written | ||||||
|
@@ -362,7 +363,7 @@ func (k Keeper) WriteAcknowledgement( | |||||
"dst_channel", packet.GetDestChannel(), | ||||||
) | ||||||
|
||||||
EmitWriteAcknowledgementEvent(ctx, packet, channel, acknowledgement) | ||||||
EmitWriteAcknowledgementEvent(ctx, packet, channel, bz) | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mock | ||
|
||
// MockEmptyAcknowledgement implements the exported.Acknowledgement interface and always returns an empty byte string as Response | ||
type MockEmptyAcknowledgement struct { | ||
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. @colin-axner Open to suggestions with this. I don't want to add technical debt unnecessarily. 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. No this is great. None of the mock code has added any technical debt so far. I think it'll be useful to keep around |
||
Response []byte | ||
} | ||
|
||
// NewMockEmptyAcknowledgement returns a new instance of MockEmptyAcknowledgement | ||
func NewMockEmptyAcknowledgement() MockEmptyAcknowledgement { | ||
return MockEmptyAcknowledgement{ | ||
Response: []byte{}, | ||
} | ||
} | ||
|
||
// Success implements the Acknowledgement interface | ||
func (ack MockEmptyAcknowledgement) Success() bool { | ||
return true | ||
} | ||
|
||
// Acknowledgement implements the Acknowledgement interface | ||
func (ack MockEmptyAcknowledgement) Acknowledgement() []byte { | ||
return []byte{} | ||
} |
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.
Shouldn't this be v3->v4?
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.
yep