Skip to content
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

Sdk v0.46.* and ibc-go v5.1.0 #349

Merged
merged 77 commits into from
Jan 11, 2023
Merged

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Nov 17, 2022

Closes: #347

Context and purpose of the change

This PR updates cosmos-sdk to v0.46.*. It shouldn't be considered ready for production until the release of v0.46.7, which deprecates all prior sdk releases.

Brief Changelog

  • update cosmos-sdk
  • update ibc-go

Author's Checklist

I have...

  • Run and PASSED locally all GAIA integration tests
  • If the change is contentful, I either:
    • Added a new unit test OR
    • Added test cases to existing unit tests
  • OR this change is a trivial rework / code cleanup without any test coverage

If skipped any of the tests above, explain.

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...

  • reviewed state machine logic
  • reviewed API design and naming
  • manually tested (if applicable)
  • confirmed the author wrote unit tests for new logic
  • reviewed documentation exists and is accurate

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md?
  • This pull request updates existing proto field values (and require a backend and frontend migration)?
  • Does this pull request change existing proto field names (and require a frontend migration)?
    How is the feature or change documented?
    • not applicable
    • jira ticket XXX
    • specification (x/<module>/spec/)
    • README.md
    • not documented

@hieuvubk hieuvubk marked this pull request as draft November 17, 2022 11:11
@asalzmann
Copy link
Contributor

Is upgrade code also required here?

@hieuvubk
Copy link
Contributor Author

Is upgrade code also required here?

Yes, we'll add upgrade handler after all bug is fixed

x/icacallbacks/module_ibc.go Outdated Show resolved Hide resolved
x/icacallbacks/module_ibc.go Outdated Show resolved Hide resolved
@@ -92,7 +94,11 @@ func (im IBCModule) NegotiateAppVersion(
}

// GetTxMsgData returns the msgs from an ICA transaction and can be reused across authentication modules
func GetTxMsgData(ctx sdk.Context, ack channeltypes.Acknowledgement, logger log.Logger) (*sdk.TxMsgData, error) {
func GetTxMsgData(ctx sdk.Context, ack channeltypes.Acknowledgement, logger log.Logger) (*types.ICATxResponse, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're on board with moving the ack unmarshaling out, I think we should add it to the top of this function and rename it to something more generic like UnpackICAAcknowledgement(I'm sure you can think of a much better name)

And then each callback would take types.ICATxResponse as the argument instead of the Ack packet type

x/stakeibc/keeper/icacallbacks_undelegate.go Outdated Show resolved Hide resolved
)
type ICATxResponse struct {
Status ICATxResponseStatus // enum of SUCCESS, TIMEOUT, FAILURE
Data sdk.TxMsgData // TxMsgData
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then I think you want data to be a byte array here

x/icacallbacks/types/ica_tx_response.go Outdated Show resolved Hide resolved
x/stakeibc/keeper/icacallbacks_undelegate.go Show resolved Hide resolved
// if ack is nil, a timeout occurred
if &ack == nil {
if &acknowledgement == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we removed logging in x/records/module_ibc.go, should we add a log here so that it's easy to see how acks are being parsed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I was thinking that as well. Might make sense to add them in after testing though cause it's still a little unclear to me which branch will wind up being timeout, error, success, etc.
I'll add a TODO for the time being

x/icacallbacks/module_ibc.go Outdated Show resolved Hide resolved
x/icacallbacks/module_ibc.go Outdated Show resolved Hide resolved
//
// It's also unclear to me whether this timeout case below is possible
// In any case, we should just test this thoughly with the following cases:
// Success
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this sequence is possible, because the host chain should process either a timeout or an error, but not both

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my biggest question is what a timeout looks like. It seems odd that we were identifying it by a nil ack. Fortunately, should be easy enough to test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We identify it with a nil ack out of convenience here https://github.com/notional-labs/stride/blob/acd8c57188652ce42c53a09c82a2d5bbe49b83af/x/stakeibc/module_ibc.go#L174

The timeout actually flows down a different code path (OnTimeout), so it probably makes sense to stop using a nil ack to identify timeouts and instead pass in an ICATxResponse with a timeout status. Sorry, should have caught this in the review - I'll push this up now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's right, good call out!

// so Acknowledgement_Result should only be returned if the transaction was successful
// However, I recall seeing a case where the acknowledgement type was Acknowledgement_Result but the transaction failed
//
// -> If my memory's correct, I think a failure on the host could come back as either an AcknowledgementError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also recall this - I think the way we tested it (as you mentioned below) was delegating to a non-existent validator?

@sampocs
Copy link
Collaborator

sampocs commented Jan 7, 2023

For testing, we can add logging at each step in the Unpack function.

And then we can test the following cases:

  • Transfer success
  • Transfer failure (hard code wrong delegation address in transfer deposit records step)
  • ICA success
  • ICA failure (hard code wrong validator address - must be a valid address but not be in the validator set)
  • ICA timeout (hard code TTL that's 1 second after current block time)

@asalzmann What am I forgetting? I think there might be two failure cases on the host - one that's rejected early by validate basic and one that's rejected after reading state from the store.
The ICA case above seems to handle the state failure. For a validate basic failure, maybe we send a Msg type that doesn't actually exist on the host or send a message with missing args?

And then for transfer I think the example above would be a validate basic failure - not sure how to invoke a state failure.

@asalzmann
Copy link
Contributor

asalzmann commented Jan 7, 2023

The above test plan makes sense - thoughts on doing this in a separate PR? This one is getting a bit hairy

I think we should probably write integration tests for these, wdyt?

@sampocs
Copy link
Collaborator

sampocs commented Jan 8, 2023

The above test plan makes sense - thoughts on doing this in a separate PR? This one is getting a bit hairy

Agreed, I don't think we should push any changes related to those tests, I think we can just do it locally. But I think we should avoid merging this to main until the integration tests pass. Maybe we get the acks working for the current v3 hosts, merge, then test a v5 host (evmos) and make relevant changes in another PR?

I think we should probably write integration tests for these, wdyt?

I think as far as the individual success/failure test cases, we should just determine the Ack packet format and then make unit tests. And then wrt integration tests, I think adding a v5 host is adequate.

@mergify mergify bot mentioned this pull request Jan 10, 2023
@mergify mergify bot mentioned this pull request Jan 10, 2023
@sampocs
Copy link
Collaborator

sampocs commented Jan 11, 2023

@asalzmann Integration tests are working. I'm trying to test restoring the channel but looks like there's some bugs in the relayer we might have to solve first.
If the new changes look good, I think we should merge this.

Also I don't see any lint errors anymore, but lmk if there was something you saw that I might be missing.

// ICA transactions have associated messages responses. IBC transfer do not.
// With ICA transactions, the schema of the response differs depending on the version of ibc-go used,
// however, this function unifies the format into a common response (a slice of byte arrays)
func UnpackAcknowledgementResponse(ctx sdk.Context, logger log.Logger, ack []byte, isICA bool) (*types.AcknowledgementResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed here, in the future we might want to encode the ack type as an enum (ICA, Transfer, etc.) so that we can support more IBC apps

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea, much cleaner! I'll actually make a quick PR for that soon

@asalzmann
Copy link
Contributor

LGTM

@asalzmann asalzmann merged commit e55f6f2 into Stride-Labs:main Jan 11, 2023
sontrinh16 pushed a commit to notional-labs/stride that referenced this pull request Mar 27, 2023
Co-authored-by: Son Trinh <sontrinh@Sons-MacBook-Pro.local>
Co-authored-by: Jacob Gadikian <jacobgadikian@gmail.com>
Co-authored-by: Aidan Salzmann <aidan@stridelabs.co>
Co-authored-by: DongLieu <duongduydongtq@gmail.com>
Co-authored-by: Nguyen Thanh Nhan <thanhnhan98qh@gmail.com>
Co-authored-by: sampocs <sam.pochyly@gmail.com>
Co-authored-by: sampocs <sam@stridelabs.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade ibc-go to v5.1.0
6 participants