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

feat: Add new opcodes endpoint #8245

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

Conversation

victor-yanev
Copy link

@victor-yanev victor-yanev commented May 7, 2024

Description:

This MR adds the following changes:

  • TransactionIdOrHashParameter
    • record used to parse and store an input parameter for transaction ID or hash.
    • validation fails if the input is neither a parsable:
      • ETH hash: ^(0x)?([0-9A-Fa-f]{64})$
      • Transaction ID: ^(\\d+)\\.(\\d+)\\.(\\d+)-(\\d{1,19})-(\\d{1,9})$
  • OpcodeSerivce:
    • contains the logic related to building ContractCallServiceParameters:
      • if an ETH hash Is passed:
        • fetches the ContractTransactionHash
        • fetches the EthereumTransaction
        • fetches the ContractResult
        • then builds the ContractCallServiceParameters from the fetched data
      • if a transaction ID is passed:
        • fetches the Transaction
        • fetches the EthereumTransaction
        • fetches the ContractResult
        • then builds the ContractCallServiceParameters from the fetched data
    • contains the logic related to building an OpcodesResponse from the OpcodesProcessingResult which is after calling ContractCallService:
      • some additional fetching is needed from EntityDatabaseAccessor to the get the EVM addresses of the sender and the receiver
  • OpcodesController:
    • can be enabled by property hedera.mirror.opcode.tracer.enabled (false by default)
    • GET: /api/v1/contracts/results/{transactionIdOrHash}/opcodes
      • calls OpcodeService to construct the CallServiceParameters from the given transactionIdOrHash
      • calls the processOpcodeCall method in ContractCallService
      • calls OpcodeService to build an OpcodesResponse from the result

More info can be found here.

Related issue(s):

Fixes #8174

Notes for reviewer:

The actual logic for ContractCallService.processOpcodeCall is currently in progress in another PR.

I've added it as an empty method which throws UnsupportedOperationException.

Tests Added

  • OpcodesControllerTests:
    • verifies the constructed CallServiceParameters for different type of transactions:
      • native transactions:
        • contract call
        • contract create
      • Ethereum transactions:
        • EIP-1559
        • EIP-2930
    • verifies the constructed OpcodesResponse with different values passed for stack, memory and storage
    • TransactionProviderEnum:
      • builds mocked Legacy, EIP-1559, EIP-2930 transactions which are used throughout the tests

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

konstantinabl and others added 4 commits May 7, 2024 18:29
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
@victor-yanev victor-yanev added the limechain Work planned for the LimeChain team label May 7, 2024
@victor-yanev victor-yanev self-assigned this May 7, 2024
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
@victor-yanev victor-yanev marked this pull request as ready for review May 14, 2024 13:51
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
@steven-sheehy
Copy link
Member

Need to also add this endpoint to the ingress routes in the web3 helm chart.

@victor-yanev
Copy link
Author

Just noticed the large gap in test coverage. Every repository and service should have a corresponding integration test (not mock).

Will be done in the PR for the integration tests.

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
# Conflicts:
#	hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/controller/ContractController.java
#	hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/service/ContractCallService.java
#	hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceTest.java
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…acheManagerRecordFileTimestamp()

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…ed for receiver and sender

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…Result

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…hParameter

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…pcodeService`

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…onIdParameterTest

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
# Conflicts:
#	docs/configuration.md
#	hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/evm/config/EvmConfiguration.java
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
…reAfterAccess`

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Copy link

sonarcloud bot commented Jun 6, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Collaborator

@xin-hedera xin-hedera left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature limechain Work planned for the LimeChain team web3 Area: Web3 API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new /api/v1/contracts/results/{transactionIdOrHash}/opcodes endpoint
6 participants