Skip to content

Conversation

@kstroobants
Copy link
Contributor

@kstroobants kstroobants commented Aug 15, 2025

Fixes #DXP-465

What

  • Introduced a comprehensive decoding mechanism for various data types in MessageHandler class.
  • Added methods to handle base64 decoding, GenVM decoding, and JSON parsing for improved data processing.
  • Enhanced _apply_log_level_truncation to include decoding logic for better log readability.

Why

To add more value to the user by making the logs readable.

Testing done

  • Tested the new decoding methods with various data inputs to ensure correct processing.
  • Created unit test.

Decisions made

Decided to only decode the contract code inside the contract state. The contract variables are not decoded because we need to know the mapping of the state variable to a hashed key and then know the type from the contract code to successfully decode it (e.g. is it a signed or unsigned int). If needed we can do this in another PR.

Checks

  • I have tested this code
  • I have reviewed my own PR
  • I have created an issue for this PR
  • I have set a descriptive PR title compliant with conventional commits

Reviewing tips

  • Focus on the new decoding methods and their integration with existing logging functionality.
  • Ensure that the decoding cannot raise errors for a specific transaction/contract.

User facing release notes

Added data decoding in logging for better readability and debugging.

Summary by CodeRabbit

  • New Features

    • Smarter, context-aware decoding for logs, including base64, JSON-embedded fields, and GenVM calldata/storage, producing more readable output.
    • Safer text detection with graceful fallbacks; non-serializable objects are converted to JSON-friendly strings.
    • Increased log preview length from 100 to 200 characters with truncation applied after decoding for clearer summaries.
  • Bug Fixes

    • Reduces garbled or unreadable log entries by avoiding invalid decodes and preserving binary data appropriately.
  • Tests

    • Extensive unit tests added covering diverse decoding cases and real log samples.

MuncleUscles and others added 13 commits August 10, 2025 19:04
This commit addresses several issues related to transaction processing and logging within the system.

- It prevents errors when updating transaction statuses or consensus data after snapshot restores by skipping updates for non-existent transactions.
- It enhances nonce handling by fetching the actual nonce from Hardhat, ensuring synchronization with the blockchain.  If not connected it falls back to existing method.
- It improves error handling during transaction forwarding, raising exceptions for nonce errors.
- It truncates large transaction fields and contract states in logs (calldata, contract_code, state) unless in DEBUG mode, reducing log size and improving readability.
- It updates gas estimation to use zkSync Era's gas limit and updates hardhat config to be the same.
- It ensures LLM and Web modules are shutdown correctly and gracefully.
- It updates the models to use the latest versions of openai, google, xai, anthropic and heuristai.
This commit addresses several issues related to transaction processing and overall system stability:

- Enhances transaction count retrieval by normalizing addresses, fetching from RPC with pending state, and gracefully falling back to the database. Includes error handling for RPC connection issues.
- Prevents errors when updating appeal processing time by checking for null `timestamp_appeal` values.
- Implements more robust process termination for LLM and Web modules, ensuring cleanup and preventing resource leaks.
- Adds custom exception classes for nonce errors in the Consensus Service, improving error handling and reporting.
- Expands allowed LLM models in provider schemas.

These changes improve the reliability and accuracy of transaction-related operations and enhance the system's resilience to external factors.
This commit adds support for forwarding Ethereum-related methods (eth_*) within batch JSON-RPC requests to a Hardhat instance.

Previously, batch requests containing eth_ methods were not handled correctly. This change ensures that such requests are forwarded to Hardhat for processing. Non-eth_ methods within batch requests are handled by Flask-JSONRPC. This allows interaction with Hardhat using batch requests.

Error handling is also implemented, now if forwarding to Hardhat fails, an error response is returned to the client.
Removes deprecated and unused provider configurations to streamline the available options.

Updates the RPC endpoint generator to improve handling of batch requests, including more robust error handling and logging, and ensures that requests are correctly forwarded to Hardhat when appropriate and not handled locally.

Also includes bug fixes for nonce checking in consensus service

Adds unit tests for batch request handling, consensus service nonce exceptions, and transaction processor improvements

BREAKING CHANGE: Removes heuristai_mistralaimixtral-8x22b-instruct, xai_grok-3-mini, and xai_grok-4-0709 providers
@kstroobants kstroobants self-assigned this Aug 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Adds a comprehensive decoding pipeline to MessageHandler for logs, including base64/GenVM/context-aware decoding, JSON-aware traversal, and serialization safeguards. Updates truncation to operate post-decoding with a higher limit. Introduces numerous private helpers. Adds extensive unit tests covering edge cases, nested structures, and JSON-serializable outputs.

Changes

Cohort / File(s) Summary
MessageHandler Decoding Pipeline
backend/protocol_rpc/message_handler/base.py
Implements recursive value decoding with key- and context-specific logic (base64, GenVM, storage slots, JSON-in-strings). Adds helpers for readability checks, fallbacks, and non-serializable conversions. Changes truncation to decoded-data path and increases default max_length to 200.
Unit Tests for Decoding
tests/unit/test_message_handler_decoding.py
Introduces comprehensive tests validating decoding across contract code, calldata, storage slots, nested structures, JSON-embedded data, GenVM detection, and serialization behavior. Includes fixtures for MessageHandler and LOG_LEVEL isolation.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Logger/Emitter
    participant MH as MessageHandler
    participant Dec as _decode_value
    participant Key as _decode_by_key/_decode_bytes_by_key
    participant JSON as _try_decode_json_with_data_fields
    participant GV as _try_decode_as_genvm
    participant TXT as _try_decode_as_text
    participant FB as _fallback_encoding

    Caller->>MH: handle_log(data)
    MH->>Dec: _decode_value(data)
    Dec->>Dec: recurse(dicts/lists)
    Dec->>Key: apply key/context rules
    alt JSON string with data fields
        Dec->>JSON: parse and decode embedded data
        JSON-->>Dec: decoded object/string
    end
    alt bytes-like content
        Key->>GV: try GenVM decode
        GV-->>Key: success/failure
        opt not GenVM / unreadable
            Key->>TXT: try text decode
            TXT-->>Key: readable text or None
            alt no readable text
                Key->>FB: hex/base64 fallback
                FB-->>Key: encoded string
            end
        end
    end
    Dec-->>MH: decoded structure
    MH->>MH: _apply_log_level_truncation(max_length=200)
    MH-->>Caller: truncated, decoded log
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I nibble bytes like clover leaves,
Turn base64 to readable sheaves;
GenVM whispers, I decode the tune,
JSON nests like a warren at noon.
With careful paws I trim the logs—
200 hops—no noisy fogs.
Thump! Clean trails through data bogs.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dxp-465-improve-terminal-logs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
78.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

coderabbitai[bot]

This comment was marked as resolved.

@kstroobants
Copy link
Contributor Author

graph TD
    A["_log_message()<br/>(line 66)"] --> B["_apply_log_level_truncation()<br/>(line 340)"]
    B --> C["_decode_value()<br/>(line 97)"]
    B --> D["_convert_non_serializable_objects()<br/>(line 316)"]
    
    C --> E["_decode_by_key()<br/>(line 126)"]
    C --> F["_try_decode_json_with_data_fields()<br/>(line 267)"]
    
    E --> G["_decode_bytes_by_key()<br/>(line 134)"]
    F --> H["_decode_json_data_fields()<br/>(line 282)"]
    
    G --> I["_decode_storage_slot()<br/>(line 205)"]
    G --> J["_is_storage_slot_key()<br/>(line 188)"]
    
    I --> K["_try_decode_as_genvm()<br/>(line 222)"]
    I --> L["_try_decode_as_text()<br/>(line 241)"]
    I --> M["_fallback_encoding()<br/>(line 249)"]
    
    L --> N["_is_readable_text()<br/>(line 256)"]
    
    style A fill:#e1f5fe
    style B fill:#f3e5f5
    style C fill:#fff3e0
    style D fill:#fff3e0
Loading

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