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

ignore redundant tx & check pending tx even if it timed out #78

Merged
merged 4 commits into from
Feb 7, 2025

Conversation

sh-cha
Copy link
Collaborator

@sh-cha sh-cha commented Feb 7, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced transaction processing for more timely and reliable status updates.
    • Improved error management that now gracefully handles missing transaction notifications, resulting in a smoother overall experience.
    • Added support for ignoring redundant transaction errors during message processing.
    • Enhanced error handling for transaction queries with new mechanisms for identifying and processing pending transactions.
  • Chores
    • Updated the job environment in the Docker workflow to a more specific version of Ubuntu.
    • Removed caching parameters from the Docker build workflow.

@sh-cha sh-cha self-assigned this Feb 7, 2025
@sh-cha sh-cha requested a review from a team as a code owner February 7, 2025 07:59
Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

This pull request refactors the pending transaction handling in the broadcaster component. In broadcaster.go, a new regular expression variable is introduced to identify "transaction not found" errors, and the previous timer-based approach in loadPendingTxs is replaced with a polling mechanism using a ticker and a select statement for improved control flow and error checking. In tx.go, an additional error type is added to the list of ignored errors for message processing. The Docker workflow configuration is updated to specify a more precise Ubuntu version and removes caching parameters.

Changes

Files Change Summary
node/broadcaster/broadcaster.go Added variable txNotFoundRegex; modified loadPendingTxs to replace timer mechanism with a polling loop using a ticker, including enhanced error handling based on regex matching and transaction state checks.
node/broadcaster/tx.go Introduced new error type opchildtypes.ErrRedundantTx to the ignoringErrors slice in the error handler to allow redundant transactions to be safely ignored.
.github/workflows/docker.yml Updated job environment from ubuntu-latest to ubuntu-22.04; removed cache-from and cache-to parameters in the Docker build step.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant LPT as loadPendingTxs
    participant Ticker as Ticker
    participant TxQuery as Tx Query
    participant Logger as Logger

    Caller->>LPT: Invoke loadPendingTxs
    loop Polling Loop
        LPT->>Ticker: Wait for next tick
        alt Context Cancelled
            Ticker-->>LPT: Context cancellation
            LPT-->>Caller: Return early
        else On Tick
            LPT->>TxQuery: Query pending transaction status
            alt Transaction Included
                TxQuery-->>LPT: Success result
                LPT->>LPT: Remove transaction from pending list
            else Transaction Error
                TxQuery-->>LPT: Error response
                alt Error matches txNotFoundRegex and timeout exceeded
                    LPT-->>Caller: Break loop and return
                else
                    LPT->>Logger: Log warning
                end
            end
        end
    end
Loading

Poem

I'm a hopping rabbit, code so neat,
With tickers and polls, our loops now beat.
Regex eyes spotting the elusive "not found",
Pending transactions no longer abound.
Redundant errors? Ignored with a playful cheer,
Celebrating clean code—hip, hooray, my dear! 🐰


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62cb37b and 8296c7d.

📒 Files selected for processing (1)
  • .github/workflows/docker.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: golangci-lint
  • GitHub Check: Run test
  • GitHub Check: opinitd
🔇 Additional comments (2)
.github/workflows/docker.yml (2)

28-28: OS Version Specification Update:
Changing "runs-on" from a generic "ubuntu-latest" to the specific "ubuntu-22.04" helps ensure a consistent and reproducible build environment, reducing potential discrepancies across builds.


63-71: Removal of Caching Parameters:
The removal of the "cache-from" and "cache-to" parameters in the "Build and push" step appears intentional per the PR objectives. Please verify that the removal aligns with your desired build performance strategy—if caching was previously used to speed up builds, you might want to confirm that its absence does not negatively impact build times or resource utilization.


🪧 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: 1

🧹 Nitpick comments (2)
node/broadcaster/broadcaster.go (2)

153-154: Ticker-based polling is a good approach.
This is a standard pattern to repeatedly poll for tasks. Ensure your polling interval (ctx.PollingInterval()) is configured to balance performance against timeliness.


167-170: Hex decode error handling.
Currently, an invalid hex transaction hash aborts further processing. If partial success is desired for remaining items, consider skipping only the problematic transaction.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c61dcd and 34d27a2.

📒 Files selected for processing (2)
  • node/broadcaster/broadcaster.go (3 hunks)
  • node/broadcaster/tx.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: opinitd
🔇 Additional comments (7)
node/broadcaster/broadcaster.go (6)

6-6: Import for regex usage looks fine.
The new "regexp" import is necessary for the pattern matching logic introduced. No issues here.


26-26: Validate error message stability.
While matching on a fixed string is acceptable, consider whether the error message might change in future CometBFT updates. If so, you may need a more robust approach or a fallback check for a specific error code.


156-159: Early return might skip final cleanup.
Exiting immediately if pendingTxs is empty prevents subsequent operations (like deleting or archiving leftover items) from running. Verify that this behavior is intended and consistent with your design.


161-165: Robust select for context cancellation.
Using a select statement with context and poll ticker is clean and allows graceful shutdown.


172-182: Handling successful transaction inclusion.
Removing the entry from both the database and the local slice ensures no retry for included transactions. This logic flow is sound.


188-193: Timeout-based break is coherent.
Once the timeout is passed, you break the loop and subsequently remove pending transactions in bulk. This matches your intended flow for "not found" transactions.

node/broadcaster/tx.go (1)

25-25: Adding redundant transaction error to ignore list.
This addition helps gracefully skip errors that indicate duplicate or already-processed transactions, preventing unnecessary re-submissions.

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM

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)
node/broadcaster/broadcaster.go (1)

149-150: Consider implementing a backoff strategy for polling.

Using a fixed polling interval might not be optimal. Consider implementing an exponential backoff strategy to reduce load on the node when transactions take longer to process.

-	pollingTimer := time.NewTicker(ctx.PollingInterval())
-	defer pollingTimer.Stop()
+	backoff := ctx.PollingInterval()
+	maxBackoff := 1 * time.Minute
+	backoffFactor := 2
+	
+	nextPoll := time.NewTimer(backoff)
+	defer nextPoll.Stop()

Then in the select statement:

-		case <-pollingTimer.C:
+		case <-nextPoll.C:
+			// Increase backoff for next iteration
+			if backoff < maxBackoff {
+				backoff = time.Duration(float64(backoff) * float64(backoffFactor))
+				if backoff > maxBackoff {
+					backoff = maxBackoff
+				}
+			}
+			nextPoll.Reset(backoff)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e8f81de and 62cb37b.

📒 Files selected for processing (1)
  • node/broadcaster/broadcaster.go (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: opinitd
🔇 Additional comments (3)
node/broadcaster/broadcaster.go (3)

26-26: LGTM! Well-structured regex pattern.

The regex pattern is correctly implemented to capture transaction hashes and is efficiently compiled at package level.


154-187: Failed transaction might loop indefinitely.

When a transaction fails (code != 0), it's added to reProcessingTxs without any limit on retries. Consider implementing a maximum retry count to prevent infinite loops.


194-200: 🛠️ Refactor suggestion

Add retry limit for reprocessing transactions.

Currently, failed transactions are reprocessed without any limit. Consider adding a retry counter to each PendingTxInfo and a maximum retry limit to prevent resource exhaustion.

 type PendingTxInfo struct {
     TxHash    string
     Sender    string
     Tx        []byte
     Timestamp int64
     Save      bool
+    RetryCount int
 }

 // In loadPendingTxs
-	if len(reProcessingTxs) != 0 {
+	maxRetries := 3  // Or configure via BroadcasterConfig
+	retriableProcessingTxs := make([]btypes.PendingTxInfo, 0)
+	for _, tx := range reProcessingTxs {
+		if tx.RetryCount < maxRetries {
+			tx.RetryCount++
+			retriableProcessingTxs = append(retriableProcessingTxs, tx)
+		} else {
+			ctx.Logger().Warn("transaction exceeded max retries",
+				zap.String("hash", tx.TxHash),
+				zap.Int("retries", tx.RetryCount))
+		}
+	}
+	if len(retriableProcessingTxs) != 0 {

Likely invalid or redundant comment.

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM

@beer-1 beer-1 merged commit e4ebae9 into main Feb 7, 2025
6 checks passed
@beer-1 beer-1 deleted the fix/ignore-redundanttx branch February 7, 2025 11:05
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.

3 participants