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

Improve Orchestrator error logs #575

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cbrit
Copy link
Member

@cbrit cbrit commented Jan 29, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error logging across multiple functions to provide more detailed context during error scenarios.
    • Improved error handling in blockchain event log retrieval to increase system robustness.
    • Added more informative error messages for Gravity ID and LogicCall submission failures.
  • Chores

    • Updated error logging mechanisms to support better debugging and troubleshooting.
    • Clarified function output by explicitly returning constructed variables in relevant functions.

@cbrit cbrit requested a review from zmanian as a code owner January 29, 2025 18:37
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request focuses on enhancing error logging and error handling across multiple Rust files in the orchestrator and relayer components. The changes involve updating error messages to include specific error details, improving the context provided during failures. Modifications span several functions, targeting operations such as retrieving block numbers, event logs, and chain IDs, as well as handling logic call submissions. Additionally, the error handling in the retrieval of blockchain event logs has been improved with a match-based approach, allowing for better recovery from transient errors.

Changes

File Change Summary
orchestrator/orchestrator/src/get_with_retry.rs Updated error logging in three async functions to include error result details for block number, event nonce, and chain ID retrieval.
orchestrator/orchestrator/src/main_loop.rs Enhanced error message for Gravity ID retrieval by including error details.
orchestrator/orchestrator/src/oracle_resync.rs Improved error handling for blockchain event log retrieval using match statements and a retry mechanism.
orchestrator/relayer/src/logic_call_relaying.rs Modified error logging for logic call submission to include specific error result.
orchestrator/relayer/src/main_loop.rs Updated error logging for Gravity ID retrieval to provide more context.
orchestrator/cosmos_gravity/src/query.rs Reformatted warning log messages for better readability without changing functionality.
orchestrator/relayer/src/batch_relaying.rs Added explicit return statement for get_batches_and_signatures function to clarify output.

Sequence Diagram

sequenceDiagram
    participant Client
    participant EthNode
    participant OracleResync
    
    Client->>EthNode: Request Event Logs
    alt Log Retrieval Successful
        EthNode-->>OracleResync: Return Event Logs
        OracleResync->>OracleResync: Process Logs
    else Log Retrieval Failed
        EthNode--xOracleResync: Error
        OracleResync->>OracleResync: Log Error
        OracleResync->>OracleResync: Delay and Retry
    end
Loading

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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

@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 (2)
orchestrator/orchestrator/src/oracle_resync.rs (1)

80-123: LGTM! Comprehensive error handling for event logs.

The implementation properly handles errors for each event type and includes retry mechanism for transient failures.

Consider reducing code duplication.

The error handling pattern is repeated for each event type. Consider extracting this into a helper function to improve maintainability.

async fn get_logs_with_retry<T>(
    eth_client: &EthClient,
    filter: &Filter,
    event_type: &str,
) -> Result<Vec<Log>, ethers::providers::ProviderError> {
    match eth_client.get_logs(filter).await {
        Ok(events) => Ok(events),
        Err(e) => {
            error!("Failed to get {} events (may be transient): {:?}", event_type, e);
            delay_for(RETRY_TIME).await;
            Err(e)
        }
    }
}

Usage example:

let erc20_deployed_events = match get_logs_with_retry(
    &eth_client,
    &erc20_deployed_filter,
    "ERC20 deployed"
).await {
    Ok(events) => events,
    Err(_) => continue,
};
orchestrator/orchestrator/src/main_loop.rs (1)

260-260: LGTM! Consider adding more context to the error message.

The addition of the error value improves debugging capabilities. However, consider adding more context about what the GravityID is used for to help operators understand the impact of this failure.

-        error!("Failed to get GravityID, check your Eth node: {:?}", gravity_id);
+        error!("Failed to get GravityID (required for message signing), check your Eth node: {:?}", gravity_id);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between de86d6e and 353d527.

⛔ Files ignored due to path filters (2)
  • orchestrator/Cargo.lock is excluded by !**/*.lock, !**/*.lock
  • orchestrator/Cargo.toml is excluded by !**/*.toml
📒 Files selected for processing (5)
  • orchestrator/orchestrator/src/get_with_retry.rs (3 hunks)
  • orchestrator/orchestrator/src/main_loop.rs (1 hunks)
  • orchestrator/orchestrator/src/oracle_resync.rs (1 hunks)
  • orchestrator/relayer/src/logic_call_relaying.rs (1 hunks)
  • orchestrator/relayer/src/main_loop.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: solidity-build
  • GitHub Check: go-build
  • GitHub Check: rust-test
  • GitHub Check: hardhat-build
  • GitHub Check: go-test
  • GitHub Check: rust-build
  • GitHub Check: local-tests (16.x)
  • GitHub Check: node-build (16.x)
  • GitHub Check: Clippy
🔇 Additional comments (5)
orchestrator/orchestrator/src/get_with_retry.rs (3)

17-17: LGTM! Improved error message clarity.

The error message now includes the actual error result, which will help with debugging Ethereum node issues.


32-32: LGTM! Enhanced error context.

Good addition of "(may be transient)" to clarify that GRPC connectivity issues could be temporary.


45-45: LGTM! Consistent error message structure.

The error message follows the same pattern as other retry functions, maintaining consistency in error reporting.

orchestrator/relayer/src/main_loop.rs (1)

27-27: LGTM! Enhanced GravityID error logging.

The error message now includes the specific error details, which will help diagnose Ethereum node connectivity issues.

orchestrator/relayer/src/logic_call_relaying.rs (1)

172-172: LGTM! Improved error visibility for logic call failures.

The error message now includes the specific error result, which will help diagnose submission failures.

Copy link

@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

🔭 Outside diff range comments (1)
orchestrator/relayer/src/batch_relaying.rs (1)

Line range hint 71-75: Enhance error logging to provide more context.

To align with the PR's objective of improving error logs, consider enhancing these error messages:

     let latest_batches = if let Ok(lb) = get_latest_transaction_batches(grpc_client).await {
         lb
     } else {
+        error!("Failed to get latest transaction batches from Cosmos: {:?}", latest_batches);
         return HashMap::new();
     };

     // ... later in the code ...

     } else {
         error!(
-            "could not get signatures for {}:{} with {:?}",
+            "Failed to retrieve batch signatures from Cosmos - Token: {}, Nonce: {}, Error: {:?}",
             batch.token_contract, batch.nonce, sigs
         );
     }

Also applies to: 89-93

🧹 Nitpick comments (8)
orchestrator/relayer/src/batch_relaying.rs (2)

109-109: LGTM! Explicit return improves code clarity.

The explicit return statement makes the function's output clearer, which is especially important for this complex function that handles batch processing and signature validation.

Consider adding a brief comment above the return statement to document what the returned HashMap represents, e.g.:

+    // Return mapping of token contracts to their submittable batches with valid signatures
     possible_batches

Line range hint 71-109: Consider implementing structured error handling.

The function could benefit from more structured error handling to improve error reporting and maintainability:

  1. Define a custom error type for batch processing:
#[derive(Debug)]
pub enum BatchProcessingError {
    FetchBatchesFailed(String),
    FetchSignaturesFailed { token: EthAddress, nonce: u64, error: String },
    InvalidSignatures { token: EthAddress, nonce: u64 },
}
  1. Update the function signature to use Result:
async fn get_batches_and_signatures(
    current_valset: Valset,
    grpc_client: &mut GravityQueryClient<Channel>,
    gravity_id: String,
) -> Result<HashMap<EthAddress, Vec<SubmittableBatch>>, BatchProcessingError>

This would provide:

  • More structured error reporting
  • Better error handling in calling code
  • Clearer error propagation paths
orchestrator/orchestrator/src/oracle_resync.rs (6)

80-90: Enhance error context for ERC20 deployed events.

While the error handling is good, consider including additional context such as the block range being searched to help with debugging.

 let erc20_deployed_events = match eth_client.get_logs(&erc20_deployed_filter).await {
     Ok(events) => events,
     Err(e) => {
         error!(
-            "Failed to get ERC20 deployed events (may be transient): {:?}",
+            "Failed to get ERC20 deployed events in block range {:?}-{:?} (may be transient): {:?}",
+            start_search_block, end_search_block,
             e
         );
         delay_for(RETRY_TIME).await;
         continue;
     }
 };

91-101: Enhance error context for logic call events.

Similar to the ERC20 events, include the block range in the error message for better debugging context.

 let logic_call_events = match eth_client.get_logs(&logic_call_filter).await {
     Ok(events) => events,
     Err(e) => {
         error!(
-            "Failed to get logic call events (may be transient): {:?}",
+            "Failed to get logic call events in block range {:?}-{:?} (may be transient): {:?}",
+            start_search_block, end_search_block,
             e
         );
         delay_for(RETRY_TIME).await;
         continue;
     }
 };

102-112: Enhance error context for send to cosmos events.

Include the block range in the error message to maintain consistency and improve debugging capabilities.

 let send_to_cosmos_events = match eth_client.get_logs(&send_to_cosmos_filter).await {
     Ok(events) => events,
     Err(e) => {
         error!(
-            "Failed to get send to cosmos events (may be transient): {:?}",
+            "Failed to get send to cosmos events in block range {:?}-{:?} (may be transient): {:?}",
+            start_search_block, end_search_block,
             e
         );
         delay_for(RETRY_TIME).await;
         continue;
     }
 };

113-123: Enhance error context for transaction batch events.

Include the block range in the error message for consistency with other event handlers.

 let transaction_batch_events = match eth_client.get_logs(&transaction_batch_filter).await {
     Ok(events) => events,
     Err(e) => {
         error!(
-            "Failed to get transaction batch events (may be transient): {:?}",
+            "Failed to get transaction batch events in block range {:?}-{:?} (may be transient): {:?}",
+            start_search_block, end_search_block,
             e
         );
         delay_for(RETRY_TIME).await;
         continue;
     }
 };

128-138: Enhance error context for valset updated events.

Given the special significance of valset events (especially nonce 0 for contract initialization), include both block range and additional context in the error message.

 let mut valset_updated_events = match eth_client.get_logs(&valset_updated_filter).await {
     Ok(events) => events,
     Err(e) => {
         error!(
-            "Failed to get valset updated events (may be transient): {:?}",
+            "Failed to get valset updated events in block range {:?}-{:?} (including potential contract initialization events) (may be transient): {:?}",
+            start_search_block, end_search_block,
             e
         );
         delay_for(RETRY_TIME).await;
         continue;
     }
 };

80-138: Consider implementing exponential backoff for retries.

While the current retry mechanism is functional, consider implementing an exponential backoff strategy for transient errors. This would help prevent overwhelming the Ethereum node during periods of instability.

You could create a helper function like this:

async fn retry_with_backoff<T, E, F: Future<Output = Result<T, E>>>(
    operation: impl Fn() -> F,
    max_retries: u32,
    initial_delay: Duration,
) -> Result<T, E> {
    let mut delay = initial_delay;
    let mut attempts = 0;
    loop {
        match operation().await {
            Ok(result) => return Ok(result),
            Err(e) => {
                attempts += 1;
                if attempts >= max_retries {
                    return Err(e);
                }
                delay_for(delay).await;
                delay *= 2; // Exponential backoff
            }
        }
    }
}

This would provide more robust handling of transient network issues.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 353d527 and 4ff05be.

📒 Files selected for processing (6)
  • orchestrator/cosmos_gravity/src/query.rs (3 hunks)
  • orchestrator/orchestrator/src/get_with_retry.rs (3 hunks)
  • orchestrator/orchestrator/src/main_loop.rs (1 hunks)
  • orchestrator/orchestrator/src/oracle_resync.rs (1 hunks)
  • orchestrator/relayer/src/batch_relaying.rs (1 hunks)
  • orchestrator/relayer/src/main_loop.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • orchestrator/cosmos_gravity/src/query.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • orchestrator/relayer/src/main_loop.rs
  • orchestrator/orchestrator/src/main_loop.rs
  • orchestrator/orchestrator/src/get_with_retry.rs
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: solidity-build
  • GitHub Check: rust-test
  • GitHub Check: go-build
  • GitHub Check: rust-build
  • GitHub Check: go-test
  • GitHub Check: Clippy
  • GitHub Check: local-tests (16.x)
  • GitHub Check: node-build (16.x)
  • GitHub Check: hardhat-build

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.

2 participants