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

fix: Update getTransactionByBlockHashOrBlockNumAndIndex to pass timestamp to MAPI calls #3049

Conversation

victor-yanev
Copy link
Contributor

@victor-yanev victor-yanev commented Oct 1, 2024

Description:

  • Updates the eth_getTransactionByBlockHashAndIndex and eth_getTransactionByBlockNumberAndIndex to pass a timestamp range of the block to subsequent calls to getContractResults

Related issue(s):

Fixes #3042

Notes for reviewer:

Checklist

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

…estamp to MAPI calls

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
@victor-yanev victor-yanev added enhancement New feature or request P1 labels Oct 1, 2024
@victor-yanev victor-yanev added this to the 0.58.0 milestone Oct 1, 2024
@victor-yanev victor-yanev self-assigned this Oct 1, 2024
Copy link

github-actions bot commented Oct 1, 2024

Acceptance Tests

  18 files  240 suites   30m 38s ⏱️
603 tests 596 ✔️ 4 💤 3
701 runs  692 ✔️ 6 💤 3

Results for commit e71182e.

♻️ This comment has been updated with latest results.

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 October 2, 2024 10:36
Copy link
Collaborator

@ebadiere ebadiere left a comment

Choose a reason for hiding this comment

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

The "Tests" seem to fail consistently:

    3 failing
  
    1) HAPI Service
         should be able to reset all counter upon reinitialization of the SDK Client:
  
        AssertionError: expected 35999 to equal 36000
        + expected - actual
  
        -35999
        +36000
        
        at Context.<anonymous> (tests/lib/hapiService.spec.ts:132:48)
        at Generator.next (<anonymous>)
        at /home/runner/_work/hedera-json-rpc-relay/hedera-json-rpc-relay/packages/relay/tests/lib/hapiService.spec.ts:27:71
        at new Promise (<anonymous>)
        at __awaiter (tests/lib/hapiService.spec.ts:23:12)
        at Context.<anonymous> (tests/lib/hapiService.spec.ts:124:20)
        at processImmediate (node:internal/timers:483:21)
  
    2) Open RPC Specification
         should execute "eth_getTransactionByBlockHashAndIndex":
       Error invoking RPC: Could not find mock for: 
  {
    "method": "get",
    "url": "contracts/results?block.hash=0x3c08bbbee74d287b1dcd3f0ca6d1d2cb92c90883c4acf9747de9f3f3162ad25b999fc7e86699f60f2a3fb3ed9a646c6b&timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&transaction.index=77&limit=100&order=asc"
  }
    
  
    3) Open RPC Specification
         should execute "eth_getTransactionByBlockNumberAndIndex":
       Error invoking RPC: Could not find mock for: 
  {
    "method": "get",
    "url": "contracts/results?block.number=3&timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&transaction.index=77&limit=100&order=asc"
  }
    ```

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

victor-yanev commented Oct 3, 2024

The "Tests" seem to fail consistently:

    3 failing
  
    1) HAPI Service
         should be able to reset all counter upon reinitialization of the SDK Client:
  
        AssertionError: expected 35999 to equal 36000
        + expected - actual
  
        -35999
        +36000
        
        at Context.<anonymous> (tests/lib/hapiService.spec.ts:132:48)
        at Generator.next (<anonymous>)
        at /home/runner/_work/hedera-json-rpc-relay/hedera-json-rpc-relay/packages/relay/tests/lib/hapiService.spec.ts:27:71
        at new Promise (<anonymous>)
        at __awaiter (tests/lib/hapiService.spec.ts:23:12)
        at Context.<anonymous> (tests/lib/hapiService.spec.ts:124:20)
        at processImmediate (node:internal/timers:483:21)
  
    2) Open RPC Specification
         should execute "eth_getTransactionByBlockHashAndIndex":
       Error invoking RPC: Could not find mock for: 
  {
    "method": "get",
    "url": "contracts/results?block.hash=0x3c08bbbee74d287b1dcd3f0ca6d1d2cb92c90883c4acf9747de9f3f3162ad25b999fc7e86699f60f2a3fb3ed9a646c6b&timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&transaction.index=77&limit=100&order=asc"
  }
    
  
    3) Open RPC Specification
         should execute "eth_getTransactionByBlockNumberAndIndex":
       Error invoking RPC: Could not find mock for: 
  {
    "method": "get",
    "url": "contracts/results?block.number=3&timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&transaction.index=77&limit=100&order=asc"
  }
    ```

@ebadiere Fixed

@victor-yanev victor-yanev requested a review from a team October 3, 2024 08:45
Copy link

github-actions bot commented Oct 3, 2024

Tests

       3 files     297 suites   19s ⏱️
1 353 tests 1 352 ✔️ 1 💤 0
1 362 runs  1 361 ✔️ 1 💤 0

Results for commit e71182e.

♻️ This comment has been updated with latest results.


export function contractResultsByNumberByIndexURL(number: number, index: number): string {
return `contracts/results?block.number=${number}&transaction.index=${index}&limit=100&order=asc`;
export function getQueryParams(params: object) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this function already exist in helpers.ts?
Could it be reused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it could be reused but it needs to be extended to also support arrays for values in the params object, I will extend it and remove this one. Thanks!


const hapiServiceInstance = new HAPIService(logger, registry, hbarLimiter, cacheService);
const hapiServiceInstance = new HAPIService(logger, registry, hbarLimiter, cacheService, eventEmitter);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like an unrelated change, is this a bug you realized that you're fixing.
Is so please update the PR description with the details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, eth-helpers.ts wasn't updated to pass the new EventEmitter parameter of HAPIService when those changes which modified the constructor were introduced, and I was getting TypeScript errors for this file.

ebadiere
ebadiere previously approved these changes Oct 3, 2024
…BlockNumAndIndex'

Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
@victor-yanev victor-yanev force-pushed the 3042-Update-eth_getTransactionByBlockHashOrBlockNumAndIndex branch from 9de65e7 to 5a1c6a0 Compare October 3, 2024 14:54
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Copy link

sonarcloud bot commented Oct 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
4.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@victor-yanev
Copy link
Contributor Author

After discussing this with xin, it seems like those changes were not needed

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.81%. Comparing base (f1794d8) to head (e71182e).

Files with missing lines Patch % Lines
packages/relay/src/lib/eth.ts 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3049      +/-   ##
==========================================
- Coverage   84.83%   84.81%   -0.02%     
==========================================
  Files          59       59              
  Lines        3937     3939       +2     
  Branches      786      787       +1     
==========================================
+ Hits         3340     3341       +1     
  Misses        357      357              
- Partials      240      241       +1     
Flag Coverage Δ
relay 84.91% <50.00%> (-0.03%) ⬇️
server 83.43% <ø> (ø)
ws-server 97.87% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/relay/src/lib/eth.ts 81.79% <50.00%> (-0.08%) ⬇️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1
Projects
None yet
3 participants