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

add a default TTL to non-periodic queries, and GC stale queries #1812

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

joe-bowman
Copy link
Contributor

@joe-bowman joe-bowman commented Jan 31, 2025

1. Summary

Periodically, ICQ queries can be emitted that - because of external factors (rpc node pruning, etc.) - cannot be satisfied. This leads to stale queries that do not get cleaned up and cause a drop in performance, as the ICQ relayer repeatedly tries to deliver them.

This PR adds a Default TTL (consider adding a per query TTL in a future release), so that stale queries can be garbage collected.

  • Set default TTL to 1000 blocks.
  • Do not delete periodic queries.
  • Take care to not delete queries that have not yet been emitted.

Summary by CodeRabbit

  • New Features

    • Introduced a time-to-live (TTL) mechanism for queries, allowing automatic deletion of non-periodic queries after a specified number of blocks.
  • Chores

    • Updated dependency versions to ensure compatibility and address potential vulnerabilities.

Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

"""

Walkthrough

The changes introduce a new constant DefaultTTL set to 1000, replacing the previous RetryInterval. The EndBlocker function is modified to include logic for deleting non-periodic queries that have not been re-emitted within the DefaultTTL block height. Additionally, the go.mod file reflects several dependency version downgrades and the addition of a new indirect dependency, github.com/opencontainers/runc, to enhance compatibility and address potential vulnerabilities.

Changes

File Change Summary
x/interchainquery/keeper/abci.go - Added new constant DefaultTTL = 1000
- Removed constant RetryInterval
- Enhanced EndBlocker function with TTL-based query deletion logic
go.mod - Downgraded dependency github.com/Crocmagnon/fatcontext from v0.7.1 to v0.6.0
- Downgraded dependency github.com/ghostiam/protogetter from v0.3.9 to v0.3.8
- Downgraded dependency github.com/golangci/revgrep from v0.7.0 to v0.5.3
- Added new dependency github.com/opencontainers/runc v1.2.0

Poem

🐰 Queries hop and queries dance,
TTL brings a cleaner chance!
One thousand blocks, then fade away,
No stale queries shall here stay.
Clean and swift, our system leaps! 🌈
"""

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 906c027 and 6daeee5.

📒 Files selected for processing (1)
  • x/interchainquery/keeper/abci.go (2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
x/interchainquery/keeper/abci.go

7-7: File is not gci-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) -s prefix(github.com/quicksilver-zone/quicksilver) --custom-order

(gci)


27-27: File is not gofumpt-ed

(gofumpt)

🪛 GitHub Check: devskim
x/interchainquery/keeper/abci.go

[notice] 27-27: A "TODO" or similar was left in source code, possibly indicating incomplete functionality
Suspicious comment

🪛 GitHub Actions: golangci-lint
x/interchainquery/keeper/abci.go

[error] 7-7: File is not properly formatted with gci. Required format: --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) -s prefix(github.com/quicksilver-zone/quicksilver) --custom-order


[error] 27-27: File is not properly formatted according to gofumpt standards

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test quicksilver (darwin, arm64)
  • GitHub Check: test quicksilver (amd64, windows)
  • GitHub Check: test quicksilver (amd64, linux)
  • GitHub Check: Analyze
🔇 Additional comments (1)
x/interchainquery/keeper/abci.go (1)

14-14: LGTM: DefaultTTL constant.

The value of 1000 blocks for the TTL seems reasonable for managing stale queries.

x/interchainquery/keeper/abci.go Show resolved Hide resolved
x/interchainquery/keeper/abci.go Outdated Show resolved Hide resolved
if !queryInfo.Period.IsNegative() && // not periodic
!queryInfo.LastEmission.IsNil() && // has been emitted
!queryInfo.LastEmission.IsZero() && // has been emitted
queryInfo.LastEmission.LT(math.NewInt(ctx.BlockHeight()-DefaultTTL)) { // TODO: add per query TTL

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
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

🧹 Nitpick comments (1)
x/interchainquery/keeper/abci.go (1)

28-28: Consider implementing per-query TTL.

The TODO comment suggests adding per-query TTL. This would provide more flexibility in query management, allowing different TTLs for different types of queries.

Would you like me to help implement this enhancement? This could involve:

  1. Adding a TTL field to the Query struct
  2. Using the query-specific TTL if set, otherwise falling back to DefaultTTL
🧰 Tools
🪛 GitHub Check: devskim

[notice] 28-28: A "TODO" or similar was left in source code, possibly indicating incomplete functionality
Suspicious comment

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6daeee5 and 47e7651.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • go.mod (4 hunks)
  • x/interchainquery/keeper/abci.go (2 hunks)
🧰 Additional context used
🪛 GitHub Check: devskim
x/interchainquery/keeper/abci.go

[notice] 28-28: A "TODO" or similar was left in source code, possibly indicating incomplete functionality
Suspicious comment

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test quicksilver (darwin, arm64)
  • GitHub Check: test quicksilver (amd64, windows)
  • GitHub Check: test quicksilver (amd64, linux)
  • GitHub Check: Analyze
🔇 Additional comments (3)
x/interchainquery/keeper/abci.go (2)

15-15: LGTM!

The constant value of 1000 blocks for the default TTL is reasonable and the naming follows Go conventions.


24-31: 🛠️ Refactor suggestion

Improve query deletion logic for better clarity and maintainability.

The current implementation has a few areas for improvement:

  1. Using Period.IsNegative() to check for non-periodic queries is counterintuitive
  2. The double check for emission (!IsNil && !IsZero) seems redundant

Consider this refactoring:

-		if !queryInfo.Period.IsNegative() && // not periodic
-			!queryInfo.LastEmission.IsNil() && // has been emitted
-			!queryInfo.LastEmission.IsZero() && // has been emitted
-			queryInfo.LastEmission.LT(math.NewInt(ctx.BlockHeight()-DefaultTTL)) { //TODO: add per query TTL
+		// Delete non-periodic queries that haven't been re-emitted within TTL
+		if queryInfo.Period.IsZero() && // non-periodic query
+			!queryInfo.LastEmission.IsNil() && // has been emitted at least once
+			queryInfo.LastEmission.LT(math.NewInt(ctx.BlockHeight()-DefaultTTL)) {

Likely invalid or redundant comment.

🧰 Tools
🪛 GitHub Check: devskim

[notice] 28-28: A "TODO" or similar was left in source code, possibly indicating incomplete functionality
Suspicious comment

go.mod (1)

69-69: LGTM!

The dependency version changes appear to be routine version management and don't directly impact the TTL implementation.

Also applies to: 152-152, 179-179, 265-265

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 63.40%. Comparing base (906c027) to head (47e7651).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
x/interchainquery/keeper/abci.go 0.00% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1812      +/-   ##
==========================================
- Coverage   63.43%   63.40%   -0.04%     
==========================================
  Files         172      172              
  Lines       15449    15457       +8     
==========================================
  Hits         9800     9800              
- Misses       4838     4846       +8     
  Partials      811      811              
Flag Coverage Δ
unittests 63.40% <0.00%> (-0.04%) ⬇️

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

Files with missing lines Coverage Δ
x/interchainquery/keeper/abci.go 13.15% <0.00%> (-3.51%) ⬇️

@joe-bowman joe-bowman merged commit 3ba2de7 into main Jan 31, 2025
15 of 17 checks passed
@joe-bowman joe-bowman deleted the gc-stale-queries branch January 31, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants