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: Allow single-quotes for arbitrage-min-gas-fee #8056

Closed

Conversation

sigv
Copy link
Contributor

@sigv sigv commented Apr 15, 2024

Closes: #8055

What is the purpose of the change

There is mempool configuration in app.toml, which includes an arbitrage minimum gas fee value. During startup, Osmosis attempts to overwrite the app.toml values file. This is done with a direct string replacement - cutting based on where the nearest quotes are. Generally this works fine, if the TOML file has standard double quotes for regular strings. However, if the TOML file has been overwritten already with tooling that uses literal strings, then the file will consist of single-quotes instead, as follows:

[osmosis-mempool]
arbitrage-min-gas-fee = '.005'

Such configuration will fail to find double-quotes and use an index of -1 for the replacement cutting, resulting in an app.toml:

[osmosis-mempool]
0.1
arbitrage-min-gas-fee = '.005'

This results in a failure to restart the Osmosis binary, as the next startup tries to parse the broken TOML file.

This could be confusing, if later in the file double-quotes are actually still used, as Osmosis binary would do the replacement there instead. Such as:

[osmosis-mempool]
arbitrage-min-gas-fee = '.005'
max-gas-wanted-per-tx = "60000000"

Becoming:

[osmosis-mempool]
arbitrage-min-gas-fee = '.005'
max-gas-wanted-per-tx = "0.1"

This commit simply looks for whether a single-quote or a double-quote is the left-most matched character, before doing a replacement operation. This ensures that even TOML files with mixed quotes are handled properly.

This commit does not implement processing of multi-line strings with """ and ''' boundaries.

Testing and Verifying

This change is a trivial rework / code cleanup without any test coverage.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a bug related to allowing single-quotes for arbitrage-min-gas-fee.
    • Enhanced flexibility in handling different quote types in the overwriteAppTomlValues function.

Copy link
Contributor

coderabbitai bot commented Apr 15, 2024

Walkthrough

The recent changes in version v24.0.1 focus on resolving a bug related to the handling of single-quotes for arbitrage-min-gas-fee in the app.toml file and enhancing flexibility in quote character detection in the overwriteAppTomlValues function within cmd/osmosisd/cmd/root.go.

Changes

File Change Summary
CHANGELOG.md, cmd/osmosisd/cmd/root.go Bug fix for allowing single-quotes for arbitrage-min-gas-fee; Updated overwriteAppTomlValues to use regex for quote detection

Assessment against linked issues

Objective Addressed Explanation
Ensure app.toml can handle different quote types in mempool configuration [#8055]
Prevent parsing failures on restart due to quote inconsistencies in app.toml [#8055]

Poem

🐰💻🌟
In the world of code, where bugs hide and play,
A rabbit hopped in, with a regex today.
Quotes of all sorts, now gracefully read,
No more crashes, our worries have fled.
Celebrate the code, robust and new,
Hooray for the updates, thanks to the crew!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sigv sigv force-pushed the single-quote-arbitrage-min-gas-fee branch 2 times, most recently from 79a382b to 42bfe66 Compare April 15, 2024 21:31
There is mempool configuration in app.toml, which includes an
arbitrage minimum gas fee value. During startup, Osmosis attempts
to overwrite the app.toml values file. This is done with a direct
string replacement - cutting based on where the nearest quotes are.
Generally this works fine, if the TOML file has standard double
quotes for regular strings. However, if the TOML file has been
overwritten already with tooling that uses literal strings, then
the file will consist of single-quotes instead, as follows:

    [osmosis-mempool]
    arbitrage-min-gas-fee = '.005'

Such configuration will fail to find double-quotes and use an index
of -1 for the replacement cutting, resulting in an app.toml:

    [osmosis-mempool]
    0.1
    arbitrage-min-gas-fee = '.005'

This results in a failure to restart the Osmosis binary, as the
next startup tries to parse the broken TOML file.

This could be confusing, if later in the file double-quotes are
actually still used, as Osmosis binary would do the replacement
there instead. Such as:

    [osmosis-mempool]
    arbitrage-min-gas-fee = '.005'
    max-gas-wanted-per-tx = "60000000"

Becoming:

    [osmosis-mempool]
    arbitrage-min-gas-fee = '.005'
    max-gas-wanted-per-tx = "0.1"

This commit simply looks for whether a single-quote or a double-quote
is the left-most matched character, before doing a replacement
operation. This ensures that even TOML files with mixed quotes
are handled properly.

This commit does not implement processing of multi-line strings
with `"""` and `'''` boundaries.
@sigv sigv force-pushed the single-quote-arbitrage-min-gas-fee branch from 42bfe66 to ac6074d Compare April 15, 2024 21:32
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Actionable comments outside the diff hunks (4)
CHANGELOG.md (4)

Line range hint 986-1064: Correct the heading levels to increment by one level at a time. Replace h4 headings with h3 where applicable.

- ####
+ ###

Line range hint 325-325: Remove the trailing punctuation in the heading.

- Initial Release!
+ Initial Release

Line range hint 588-646: Replace bare URLs with proper markdown links to improve readability and accessibility.

- https://github.com/osmosis-labs/osmosis/releases/tag/v3.1.0
+ [v3.1.0](https://github.com/osmosis-labs/osmosis/releases/tag/v3.1.0)
- https://github.com/osmosis-labs/osmosis/releases/tag/v1.0.1
+ [v1.0.1](https://github.com/osmosis-labs/osmosis/releases/tag/v1.0.1)

Line range hint 1227-1227: Ensure that all links have appropriate text descriptions for accessibility and clarity.

- [v1.0.0]()
+ [v1.0.0](https://github.com/osmosis-labs/osmosis/releases/tag/v1.0.0)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Actionable comments outside the diff hunks (4)
CHANGELOG.md (4)

Line range hint 325-325: Remove trailing punctuation in heading for consistency with other headings.

- ## v23.0.12-iavl-v1.
+ ## v23.0.12-iavl-v1

Line range hint 588-588: Convert bare URL to a markdown link for better readability and to avoid direct exposure of raw URLs.

- * [#7994](https://github.com/osmosis-labs/osmosis/pull/7994) Async pruning for IAVL v1
+ * [#7994](https://github.com/osmosis-labs/osmosis/pull/7994)[Async pruning for IAVL v1](https://github.com/osmosis-labs/osmosis/pull/7994)

Line range hint 646-646: Convert bare URL to a markdown link for consistency and improved presentation.

- * [#525](https://github.com/osmosis-labs/cosmos-sdk/pull/525) CacheKV speedups
+ * [#525](https://github.com/osmosis-labs/cosmos-sdk/pull/525)[CacheKV speedups](https://github.com/osmosis-labs/cosmos-sdk/pull/525)

Line range hint 1227-1227: Ensure there are no empty links in the document to maintain the integrity and usefulness of the links.

- * [Link description]()
+ * [Link description](https://example.com)  # Replace with actual URL

CHANGELOG.md Show resolved Hide resolved
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

LGTM good catch!

@sigv
Copy link
Contributor Author

sigv commented Apr 17, 2024

@mattverse, thank you

I do not think backporting is needed. Could a V:state/compatible/no_backport label be added to this PR?

How should I proceed with the e2e tests failing to auth with Docker Hub?

@mattverse mattverse added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v24.x backport patches to v24.x branch labels Apr 18, 2024
@mattverse
Copy link
Member

@sigv I actually think it'd be nice if we can backport this to v24.x, added the label. I'll rerun the CI for you for e2e

Copy link
Collaborator

@PaddyMc PaddyMc left a comment

Choose a reason for hiding this comment

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

Nice catch

@czarcas7ic
Copy link
Member

Hey @sigv! Really appreciate the PR. I took some time to look into this though and I think this needs to just be refactored (we shouldn't be relying on searching the file and instead should just be unmarshaling it into the proper struct)

The refactor I did here solves the issue you pointed out, some other lingering issues, as well as makes it more readable.

Again, appreciate the PR! Just think this code was in need of change for a while now.

@czarcas7ic
Copy link
Member

Confirmed #8118 fixes this along with abstracts the logic to make future config overwrites much easier. Thanks again for the PR to highlight the issue!

@czarcas7ic czarcas7ic closed this Apr 23, 2024
@sigv sigv deleted the single-quote-arbitrage-min-gas-fee branch April 24, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v24.x backport patches to v24.x branch V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: app.toml file with literal string for osmosis-mempool.arbitrage-min-gas-fee gets broken on startup
4 participants