Repository navigation
fix(apps/transfer): print the transfer amount in the invalid amount error - #9177
Open
im-xiangda-li wants to merge 1 commit into
Open
im-xiangda-li wants to merge 1 commit into
im-xiangda-li wants to merge 1 commit into
Conversation
…rror
`Token.Validate` formatted the parsed amount with `%d`. `sdkmath.Int`
wraps a `*big.Int` and implements `String()`, but not `fmt.Formatter`, so
`%d` printed the address of the internal pointer instead of the amount:
amount must be strictly positive: got {102013986923936}
The message therefore never showed the offending amount, and it differed
between runs and between nodes. On a receive of a packet with amount "0"
the text ends up in the error acknowledgement emitted by the transfer
module, so different nodes emitted different event attributes for the same
packet.
Format the amount with `%s` so the error contains the actual value.
Fixes lfdt-ibc#9130
Co-Authored-By: MiniMax M3.1 Flash <noreply@minimax.io>
Signed-off-by: Xiangda Li <102507799+im-xiangda-li@users.noreply.github.com>
|
This PR does not match any of the 1 configured review trigger rule. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Token.Validateinmodules/apps/transfer/types/token.goformatted the parsed transfer amount with%d:sdkmath.Intis a struct that wraps a*big.Int. It implementsString(), but notfmt.Formatter, so%dprints the struct's pointer field as a decimal number instead of the amount:The error text therefore never showed the offending amount, and it changed between runs and between nodes. When a packet with amount
"0"is received, this text ends up in the error acknowledgement that the transfer module emits, so different nodes emitted different event attributes for the same packet. The acknowledgement bytes themselves are built from the error code only, so state and the app hash are not affected.This PR formats the amount with
%s, which usesInt.String(), so the error message contains the actual amount:Fixes #9130
Checklist
Test
A regression test was added in
modules/apps/transfer/types/token_test.go:The test asserts that the error message contains the actual amount and that the internal
math.Intstruct is not printed.Before this change the same test fails, showing the pointer address reported in the issue:
The full package test suite,
gofmtandgo vetpass as well: