Skip to content

do not save non-existing to_address as null address #207

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

Merged

Conversation

iuwqyir
Copy link
Collaborator

@iuwqyir iuwqyir commented May 21, 2025

TL;DR

Changed how null transaction recipients are handled in the codebase.

What changed?

  • Modified serializeTransaction function to directly assign the to field value without replacing empty values with a zero address
  • Added a new constant ZERO_BYTES_42 for handling empty address strings
  • Updated the scanTransaction function to convert zero-byte address strings back to empty strings when retrieving transaction data

How to test?

  1. Process transactions with null recipients (contract creation transactions)
  2. Verify that these transactions have empty ToAddress fields instead of zero addresses
  3. Confirm that transactions can be properly retrieved from storage with the correct representation of null recipients

Why make this change?

This change provides a more accurate representation of contract creation transactions, which have no recipient address. Instead of replacing empty recipient addresses with the zero address (0x0000000000000000000000000000000000000000), the code now preserves the empty value, making it clearer when a transaction is creating a contract versus sending to the zero address.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of transactions with missing or zero-filled "to" addresses, ensuring these are now consistently represented as empty strings in relevant cases.

Copy link

coderabbitai bot commented May 21, 2025

Walkthrough

The changes update the handling of empty or zero "to" addresses in transaction serialization and deserialization. The serializer now assigns the "to" address directly without substituting a zero address, while the deserializer replaces a 42-byte zero "to" address with an empty string. A new constant for the zero address is introduced.

Changes

File(s) Change Summary
internal/rpc/serializer.go Modified serializeTransaction to remove substitution of empty/missing "to" address with zero address; now assigns directly.
internal/storage/clickhouse.go Added ZERO_BYTES_42 constant; updated scanTransaction to replace 42-byte zero ToAddress with an empty string.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Serializer
    participant Deserializer

    Client->>Serializer: serializeTransaction(txMap)
    Serializer-->>Client: Transaction (with "to" assigned directly)

    Client->>Deserializer: scanTransaction(rows)
    Deserializer->>Deserializer: Check if ToAddress == ZERO_BYTES_42
    alt ToAddress is zero
        Deserializer->>Deserializer: Replace ToAddress with ""
    end
    Deserializer-->>Client: Transaction (with processed ToAddress)
Loading

📜 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 92af676 and 03864f8.

📒 Files selected for processing (2)
  • internal/rpc/serializer.go (1 hunks)
  • internal/storage/clickhouse.go (2 hunks)
🔇 Additional comments (3)
internal/rpc/serializer.go (1)

178-178: Improved handling of contract creation transactions

This change correctly keeps the original empty value for the ToAddress field rather than replacing it with the zero address. This ensures that contract creation transactions (which have no recipient) are properly represented with an empty address string rather than 0x0000...0000.

internal/storage/clickhouse.go (2)

35-35: LGTM: New constant for handling zero addresses

The new ZERO_BYTES_42 constant properly defines a 42-byte zero-filled string that will be used to detect zero addresses in the scan function.


753-755: Properly converts zero addresses back to empty strings

This change complements the serializer modification by ensuring that when reading transactions from the database, any 42-byte zero address strings are converted back to empty strings. This maintains consistency between how empty addresses are handled during serialization and deserialization.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@iuwqyir iuwqyir requested a review from catalyst17 May 21, 2025 12:29
Copy link
Collaborator Author

iuwqyir commented May 21, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@iuwqyir iuwqyir marked this pull request as ready for review May 21, 2025 12:30
Copy link
Contributor

the only issue I'm worried about here are transactions which legit target zero address, we should somehow keep them as is no?

@iuwqyir
Copy link
Collaborator Author

iuwqyir commented May 21, 2025

the only issue I'm worried about here are transactions which legit target zero address, we should somehow keep them as is no?

Those will be saved as zero addresses, because RPC returns them as such.

@iuwqyir iuwqyir merged commit f520cfc into main May 21, 2025
6 checks passed
@iuwqyir iuwqyir deleted the 05-21-do_not_save_non-existing_to_address_as_null_address branch May 21, 2025 12:48
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