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

fix(tm2): Fix the endpoint /tx?hash= to make it work #2518

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

linhpn99
Copy link
Contributor

@linhpn99 linhpn99 commented Jul 6, 2024

From issue : #2489

I found an issue with the code segment parsing arguments from the request that did not support base64 encoding, so I implemented logic to handle it. If there are any inconsistencies, please share the opinion

Screenshot from 2024-07-06 12-00-09

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

Copy link

codecov bot commented Jul 6, 2024

Codecov Report

Attention: Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.

Project coverage is 60.45%. Comparing base (f04ec89) to head (b6f7471).

Files with missing lines Patch % Lines
tm2/pkg/bft/rpc/lib/server/handlers.go 72.72% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2518      +/-   ##
==========================================
+ Coverage   60.44%   60.45%   +0.01%     
==========================================
  Files         563      563              
  Lines       75159    75092      -67     
==========================================
- Hits        45427    45398      -29     
+ Misses      26343    26309      -34     
+ Partials     3389     3385       -4     
Flag Coverage Δ
contribs/gnodev 60.65% <ø> (-0.82%) ⬇️
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
gno.land 67.21% <ø> (ø)
gnovm 64.46% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (+0.35%) ⬆️
tm2 62.11% <72.72%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@linhpn99 linhpn99 changed the title fix(tm2): Fix the endpoint /tx?hash= so that it is usable fix(tm2): Fix the endpoint /tx?hash= to make it work Jul 6, 2024
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

Thanks, some work to be done for a proper fix.

tm2/pkg/bft/rpc/lib/server/handlers.go Show resolved Hide resolved
@linhpn99 linhpn99 requested a review from thehowl July 7, 2024 16:06
Comment on lines 379 to 381
// Handle int string
if reInt.Match([]byte(arg)) {
arg = fmt.Sprintf("%q", arg)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this necessary? I think things like height= values will be parsed incorrectly if we have this...

Copy link
Contributor Author

@linhpn99 linhpn99 Aug 1, 2024

Choose a reason for hiding this comment

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

No, I only quote in the case of integers. You need to format it as a JSON string by quoting it; otherwise, you will encounter an error when calling UnmarshalJSON

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the data is a raw number (e.g., -10) and you pass it directly as json.RawMessage, it will be interpreted as a JSON number, not as a string

Comment on lines 367 to 372
// Handle base64 string
if decoded, err := base64.StdEncoding.DecodeString(arg); err == nil {
data, err := amino.MarshalJSON(decoded)
if err != nil {
return nil, errors.Wrap(err, "error marshaling argument to JSON")
}
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this

  1. many strings will be decodable as base64 when they shouldn't be.
  2. for /tx?hash= specifically, it will work; the decoding will be handled by amino.UnmarshalJSON in mapParamsToArgs, as long as the string is quoted here

Copy link
Contributor Author

@linhpn99 linhpn99 Aug 1, 2024

Choose a reason for hiding this comment

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

@leohhhn
Copy link
Contributor

leohhhn commented Sep 11, 2024

#2333 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

3 participants