Skip to content

Create ValidationOptions for each tx submission#818

Merged
j1010001 merged 2 commits into
mainfrom
mpeter/fix-pectra-rules-tx-validation
May 9, 2025
Merged

Create ValidationOptions for each tx submission#818
j1010001 merged 2 commits into
mainfrom
mpeter/fix-pectra-rules-tx-validation

Conversation

@m-Peter
Copy link
Copy Markdown
Collaborator

@m-Peter m-Peter commented May 8, 2025

Description

Previously this Header time was only created during startup, so it never got updated. This makes the EVM GW think that we're not yet in Pectra:

curl -XPOST 'https://testnet.evm.nodes.onflow.org' --header 'Content-Type: application/json' --data-raw '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0x04f8c982022101800183016b1e94fe847d8bebe46799fce83eb52f38ef4b907996a680848129fc1cc0f85ef85c82022194313af46a48eeb56d200fae0edb741628255d379f0101a0f354c695f1a6fe9bc7655aa220bbc51a6c000a4221efb5d2e848f85918353524a0693de7bd731004910396bc7753ad13e11b90a350fb84128fda6d6439584836d880a0bdade120008921fd57b6d6999e983c84e0a8efdfb3bb282c80886b05e8b1fc3ea074c4362fd383323f7efc166ebe1ebc869c8909d97f8a8d6414b03a020a60d92b"],"id":2}' | jq
{
  "jsonrpc": "2.0",
  "id": 2,
  "error": {
    "code": -32000,
    "message": "transaction type not supported: type 4 rejected, pool not yet in Prague"
  }
}

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor
    • Improved transaction processing reliability by using a fresh context for each transaction submission, reducing reliance on stored state.

@m-Peter m-Peter self-assigned this May 8, 2025
@m-Peter m-Peter added the Bug Something isn't working label May 8, 2025
@m-Peter m-Peter added the EVM label May 8, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2025

Walkthrough

The changes remove persistent storage of the head, evmSigner, and validationOptions fields from the EVM struct. Instead, these are now instantiated locally within the SendRawTransaction method each time it is called, eliminating reliance on stored state for transaction validation.

Changes

File(s) Change Summary
services/requester/requester.go Removed head, evmSigner, and validationOptions fields from EVM struct; updated NewEVM constructor to not initialize these fields; modified SendRawTransaction to create them locally for each call.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant EVM
    participant EmulatorConfig
    participant TxValidator

    Client->>EVM: SendRawTransaction(ctx, data)
    EVM->>EVM: Create new head, emulatorConfig, evmSigner, validationOptions
    EVM->>TxValidator: Validate transaction with local context
    TxValidator-->>EVM: Validation result
    EVM-->>Client: Return transaction hash or error
Loading

Possibly related PRs

Suggested labels

Improvement

Suggested reviewers

  • peterargue
  • ramtinms

Poem

In the warren of code, we hop and we prance,
No more old state—each transaction gets a chance!
Fresh headers and signers for every new run,
Validation ephemeral, bugs on the run.
The garden is tidy, the carrots aligned—
Hooray for the code, so cleverly designed! 🥕

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 33287ab and 45de8d3.

📒 Files selected for processing (1)
  • services/requester/requester.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/requester/requester.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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.

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.

Copy link
Copy Markdown
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)
services/requester/requester.go (1)

186-208: Consider making the reference block number configurable

While the fixed block number (20,182,324) works for the current implementation, consider making this configurable to avoid hardcoding values that might need to change in future upgrades.

-	head := &types.Header{
-		Number:     big.NewInt(20_182_324),
+	head := &types.Header{
+		Number:     big.NewInt(e.config.ReferenceBlockNumber),

This would require adding a ReferenceBlockNumber field to your config struct.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c6ae29a and 33287ab.

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

112-114: Good removal of the stored state fields

Removing the persistent storage of head, evmSigner, and validationOptions fields from the EVM struct is the right approach. This eliminates the issue where these values were only initialized at startup and never updated.


163-173: Constructor changes match struct modifications

The removal of field initializations from the NewEVM constructor correctly aligns with the field removals from the struct definition.


186-208: Per-transaction validation context is a good solution

Creating a fresh validation context for each transaction submission ensures the Header time is current. This correctly addresses the issue where transaction submissions of type 4 were being rejected due to outdated Prague/Pectra upgrade phase detection.

The fixed block number (20,182,324) appears to be a safe reference point for validation. The current timestamp ensures accurate upgrade phase detection.


209-209: Transaction validation now uses fresh context

Using the locally created values for transaction validation ensures that validation decisions are based on current conditions rather than stale state.

@j1010001 j1010001 requested a review from Kay-Zee May 8, 2025 21:38
Comment thread services/requester/requester.go Outdated

if err := models.ValidateTransaction(tx, e.head, e.evmSigner, e.validationOptions); err != nil {
head := &types.Header{
Number: big.NewInt(20_182_324),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this block number hardcoded?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This one is not really important, as it's no longer used for hard-forks. Ethereum does upgrades with timestamps, instead of block numbers. But this is there for backwards-compatibility. I think this was the Ethereum mainnet latest block number, when we launched Flow EVM on mainnet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@m-Peter please add that as a comment, magic numbers not good :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@j1010001 Good point 👍
I added some comments which better describe the intent, in this commit: 45de8d3 .

Copy link
Copy Markdown
Member

@zhangchiqing zhangchiqing left a comment

Choose a reason for hiding this comment

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

Thanks for the fix

@j1010001 j1010001 merged commit ae4a2c6 into main May 9, 2025
2 checks passed
@j1010001 j1010001 deleted the mpeter/fix-pectra-rules-tx-validation branch May 9, 2025 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working EVM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants