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

imp: Use json for marshalling/unmarshalling transfer packet data. #5778

Merged
merged 5 commits into from
Feb 1, 2024

Conversation

DimitrisJim
Copy link
Contributor

Cleans up final usage of MustSortJSON. Uses json for marshalling/unmarshalling FungibleTokenPacketData.

closes: #3915


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@DimitrisJim DimitrisJim changed the title Use json for marshalling/unmarshalling transfer packet data. imp: Use json for marshalling/unmarshalling transfer packet data. Jan 31, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (1c0c756) 81.59% compared to head (b8b38a2) 81.61%.
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5778      +/-   ##
==========================================
+ Coverage   81.59%   81.61%   +0.02%     
==========================================
  Files         199      199              
  Lines       15167    15146      -21     
==========================================
- Hits        12375    12362      -13     
+ Misses       2326     2319       -7     
+ Partials      466      465       -1     
Files Coverage Δ
...interchain-accounts/controller/keeper/handshake.go 83.70% <100.00%> (ø)
...ules/apps/27-interchain-accounts/types/metadata.go 79.79% <100.00%> (ø)
modules/apps/transfer/types/codec.go 100.00% <ø> (+13.79%) ⬆️
modules/core/03-connection/keeper/verify.go 80.36% <100.00%> (ø)
modules/core/03-connection/types/connection.go 100.00% <ø> (+10.16%) ⬆️
modules/core/04-channel/keeper/handshake.go 90.20% <100.00%> (ø)
modules/core/04-channel/keeper/timeout.go 95.39% <100.00%> (ø)
modules/core/04-channel/keeper/upgrade.go 92.46% <100.00%> (ø)
modules/apps/transfer/types/packet.go 88.63% <50.00%> (-4.05%) ⬇️
modules/apps/transfer/ibc_module.go 69.47% <25.00%> (ø)

// GetBytes is a helper for serialising
// GetBytes is a helper for serialising the packet to bytes.
// The memo field of FungibleTokenPacketData is marked with the JSON omitempty tag
// ensuring that the memo field is not included in the marshalled bytes if one is not specified.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

though one thing I did notice is that Unmarshal seems to work just fine using an old type w/o memo defined even if marshalled bytes contain the memo, i.e:

// Check that we can unmarshal into another type that does not have memo defined
type PacketData struct {
	Denom    string `json:"denom"`
	Amount   string `json:"amount"`
	Sender   string `json:"sender"`
	Receiver string `json:"receiver"`
}

ftpdWithMemo = types.FungibleTokenPacketData{
	Denom:    denom,
	Amount:   amount,
	Sender:   sender,
	Receiver: receiver,
	Memo:     "{memo: \"test\"}",
}

bz, err = json.Marshal(ftpdWithMemo)
suite.Require().NoError(err)

var packetData2 PacketData
err = json.Unmarshal(bz, &packetData2)

suite.Require().NoError(err)

no clue if this is the case with jsonpb tho

Copy link
Contributor

Choose a reason for hiding this comment

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

must be an additional check done when marshaling protoJSON

suite.Require().NoError(err)

// check that the memo field is not present in the marshalled bytes
suite.Require().NotContains(string(bz), "memo")
Copy link
Contributor

Choose a reason for hiding this comment

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

just to double check, if you did have the memo set to "abc", this would fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea! just added an additional commit to do that check.

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Nice! ACK pending comment regarding test failing if memo is included with non "memo" value

@colin-axner
Copy link
Contributor

We can open a pr to SDK to remove the MustSortJSON since they added it back at our request

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Looks good to me! This is a really nice improvement if it means no more codec shenanigans, so much simpler using stdlib json.

I would be interested to see a compatability test run at some point with older ibc-go versions just to settle my paranoia.

@DimitrisJim
Copy link
Contributor Author

DimitrisJim commented Jan 31, 2024

I would be interested to see a compatability test run at some point with older ibc-go versions just to settle my paranoia.

yup! will work on having compat tests run on schedule soon, will run one before merging (later tonight)

@DimitrisJim
Copy link
Contributor Author

compatibility tests be green https://github.com/cosmos/ibc-go/actions/runs/7731257280

triggered manually based on my branch, release branch to test set to main based on workflow dispatch options

@crodriguezvega crodriguezvega merged commit dbc11b5 into main Feb 1, 2024
66 checks passed
@crodriguezvega crodriguezvega deleted the jim/3915-use-json-for-transfer-packet-data branch February 1, 2024 09:39
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.

Change ics20 packet data to use standard json library for marshaling
5 participants