Skip to content

Conversation

@kstroobants
Copy link
Contributor

@kstroobants kstroobants commented Jul 3, 2025

Fixes #DXP-170

What

  • Implemented a refund mechanism to restore the balance of the recipient account when a validator appeal is successful.
  • Updated refund the balance when a transaction is rollbacked.
  • Modified the restore_stuck_transactions function to include balance restoration logic.
  • Enhanced unit tests in test_base.py to verify the new refund functionality.

Why

To ensure that the recipient's account balance is correctly restored when a validator appeal is successful.

Testing done

Added and executed unit tests in test_base.py to verify that account balances are correctly restored after successful appeals.

Decisions made

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

Depends

This PR contains code from PR #1036

User facing release notes

Implemented restoring of the contract balance when appealed or recomputed.

Summary by CodeRabbit

  • New Features

    • Users can now specify a value (ETH/wei) when invoking payable contract methods in the simulator UI.
    • Accounts are automatically funded with a default balance upon creation or when importing a MetaMask account with zero balance.
    • Added support for funding and retrieving account balances via new service methods.
  • Improvements

    • Enhanced error handling and user notifications during account creation.
    • Simulator contract interactions now support dynamic value transfer for payable methods.
    • Underlying contract and account state management is more robust, ensuring accurate balance updates during transactions and rollbacks.
  • Bug Fixes

    • Ensured account balances are correctly updated and restored during transaction processing, appeals, and rollbacks.
  • Chores

    • Upgraded frontend dependency "genlayer-js" to version ^0.13.0.
  • Tests

    • Updated and extended tests to cover new balance management and funding logic for accounts.

…ling

- Implement value transfer between accounts in consensus
- Add error handling for insufficient balance in transactions
- Update GenVM to support transaction value parameter
- Add automatic account funding when creating new accounts in frontend
- Add error handling for transaction processing in RPC endpoints
- Update frontend components to handle account creation asynchronously
… into 1028-feat-adjust-value-in-current_state-based-on-transaction-values
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

This change set introduces unified and explicit handling of account balances and transaction values across the backend, frontend, smart contracts, and tests. It revises balance update logic, adds error handling, enables value transfer with contract calls, updates interfaces to support these features, and synchronizes contract and account state management in tests. Frontend components and services are extended to support account funding and value input for contract calls.

Changes

Cohort / File(s) Change Summary
Consensus & Account Balance Logic
backend/consensus/base.py, backend/database_handler/accounts_manager.py, backend/protocol_rpc/endpoints.py, backend/protocol_rpc/server.py, backend/rollup/consensus_service.py
Refactored account balance handling: explicit balance update methods, error handling for insufficient funds, unified balance update calls, and added Hardhat account funding.
Node & VM Contract Execution
backend/node/base.py, backend/node/genvm/base.py
Added transaction value parameter to contract execution flow, updating method signatures and value propagation to the VM host.
Frontend Account Funding & Value Input
frontend/src/components/Simulator/AccountSelect.vue, frontend/src/components/Simulator/ContractMethodItem.vue, frontend/src/hooks/useContractQueries.ts, frontend/src/hooks/useSetupStores.ts, frontend/src/services/IJsonRpcService.ts, frontend/src/services/JsonRpcService.ts, frontend/src/stores/accounts.ts
Enabled account funding and balance retrieval via RPC, made account creation async with conditional funding, added value input for payable contract methods, and updated hooks/services to support these features.
Frontend Dependency Update
frontend/package.json
Bumped "genlayer-js" dependency version from ^0.10.0 to ^0.13.0.
Smart Contract & Interface Updates
hardhat/contracts/v2_contracts/ConsensusMain.sol, hardhat/contracts/v2_contracts/ghost_contracts/GhostFactory.sol, hardhat/contracts/v2_contracts/interfaces/IConsensusMain.sol, hardhat/contracts/v2_contracts/interfaces/IGhostFactory.sol
Made contract methods payable and updated function signatures to accept value and explicit parameters for transaction handling.
Backend & Frontend Test Adaptation
frontend/test/unit/stores/accounts.test.ts, tests/db-sqlalchemy/accounts_manager_test.py, tests/unit/consensus/test_base.py, tests/unit/consensus/test_helpers.py
Refactored tests to use new account and contract state management, added balance assertions, updated mocks, and adapted to async account creation and funding logic.

Sequence Diagram(s)

Value Transfer During Contract Execution

sequenceDiagram
    participant User
    participant Frontend
    participant Backend (RPC)
    participant AccountsManager
    participant Node
    participant GenVMHost

    User->>Frontend: Initiate contract call (with value)
    Frontend->>Backend (RPC): send_raw_transaction / callWriteMethod (with value)
    Backend (RPC)->>AccountsManager: update_account_balance(sender, -value)
    AccountsManager-->>Backend (RPC): Success/Failure
    Backend (RPC)->>Node: run_contract(..., transaction_value=value)
    Node->>GenVMHost: run_contract(..., value)
    GenVMHost-->>Node: Execution result
    Node-->>Backend (RPC): Receipt
    Backend (RPC)-->>Frontend: Response
    Frontend-->>User: Show result
Loading

Account Creation and Funding

sequenceDiagram
    participant User
    participant Frontend
    participant JsonRpcService
    participant Backend (RPC)
    participant AccountsManager
    participant ConsensusService

    User->>Frontend: Create new account
    Frontend->>JsonRpcService: generateNewAccount()
    JsonRpcService->>Backend (RPC): Create account
    Backend (RPC)->>AccountsManager: create_new_account_with_address()
    AccountsManager->>ConsensusService: fund_hardhat_account(address, amount)
    ConsensusService-->>AccountsManager: Done
    AccountsManager-->>Backend (RPC): Account created
    Backend (RPC)-->>JsonRpcService: Account info
    JsonRpcService-->>Frontend: Account info
    Frontend-->>User: Notify account created
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • cristiam86

Poem

A hop, a skip, a balance check,
With value flowing, what the heck!
Accounts are funded, tests are run,
Contracts now accept some fun.
The code is neat, the logic sound—
This rabbit’s joy just knows no bound!
🐇💸✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ 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-170-feat-on-appeal-or-failure-revert-it-to-the-previous-value

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.
    • 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 generate unit tests to generate unit tests for 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.

@kstroobants kstroobants self-assigned this Jul 3, 2025
@kstroobants kstroobants changed the title Dxp 170 feat on appeal or failure revert it to the previous value feat: on appeal or failure revert it to the previous value Jul 3, 2025
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@kstroobants kstroobants requested a review from cristiam86 July 3, 2025 13:05
…saction-values into dxp-170-feat-on-appeal-or-failure-revert-it-to-the-previous-value
@kstroobants kstroobants removed the request for review from cristiam86 July 23, 2025 05:50
coderabbitai[bot]

This comment was marked as resolved.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants