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

[rpc] add RPC API contract.resolve_module_function_index #3464

Merged

Conversation

coldnight
Copy link
Contributor

Related #3450.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: #3450.

What is the new behavior?

  • Add an new RPC API that could resolve function index from CompiledModule.

  • Here is an example invocation in my own environment(deployed a toy mycounter contract)

    $ curl 'http://localhost:9850/' -X POST -H 'Content-Type: application/json' --data-raw '{"method":"contract.resolve_module_function_index","params":["0x43c83253e82b2667760caa005bfe4e36::MyCounter", 0],"id":56,"jsonrpc":"2.0"}'
  • The result I got

    {
      "jsonrpc": "2.0",
      "result": {
        "args": [
          {
            "doc": "",
            "name": "p0",
            "type_tag": {
              "Reference": [
                false,
                "Signer"
              ]
            }
          }
        ],
        "doc": "",
        "module_name": {
          "address": "0x43c83253e82b2667760caa005bfe4e36",
          "name": "MyCounter"
        },
        "name": "incr",
        "returns": [],
        "ty_args": []
      },
      "id": 56
    }
    

Other information

@coldnight
Copy link
Contributor Author

Hold on please, it'll cause panic if the function_index is overflow.

@coldnight coldnight force-pushed the feat-resolve-module-function-index branch from 2c7fa5d to 172a6ae Compare June 14, 2022 04:06
@coldnight
Copy link
Contributor Author

Hold on please, it'll cause panic if the function_index is overflow.

$  curl 'http://localhost:9851/' -X POST -H 'Content-Type: application/json' --data-raw '{"method":"contract.resolve_module_function_index","params":["0x3c7430c3c2a3979a703f52d3eca3ae67::MyCounter", 4],"id":56,"jsonrpc":"2.0"}'
{
  "error": {
    "code": -32603,
    "message": "Function index 4 out of range in ModuleId { address: 0x3c7430c3c2a3979a703f52d3eca3ae67, name: Identifier(\"MyCounter\") }"
  },
  "id": 56,
  "jsonrpc": "2.0"
}

@jolestar jolestar requested review from jolestar, nkysg and nanne007 June 14, 2022 05:25
@jolestar jolestar linked an issue Jun 14, 2022 that may be closed by this pull request
@jolestar
Copy link
Member

@coldnight Please help to add a unit test for resolve_module_function_index

@coldnight
Copy link
Contributor Author

@jolestar Unit tests have been added.

@codecov
Copy link

codecov bot commented Jun 14, 2022

Codecov Report

Merging #3464 (17f6d55) into master (2d55f96) will increase coverage by 0.02%.
The diff coverage is 7.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3464      +/-   ##
==========================================
+ Coverage   31.95%   31.96%   +0.02%     
==========================================
  Files         500      500              
  Lines       46806    46833      +27     
  Branches    21306    21327      +21     
==========================================
+ Hits        14951    14966      +15     
- Misses      17693    17698       +5     
- Partials    14162    14169       +7     
Flag Coverage Δ
unittests 31.96% <7.41%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
rpc/api/src/contract_api.rs 11.12% <0.00%> (-0.65%) ⬇️
rpc/server/src/module/contract_rpc.rs 3.54% <0.00%> (-0.16%) ⬇️
abi/resolver/src/lib.rs 31.28% <11.77%> (-1.28%) ⬇️
...m/types/src/account_config/events/config_change.rs 66.67% <0.00%> (-33.33%) ⬇️
vm/vm-runtime/src/metrics.rs 29.17% <0.00%> (-4.16%) ⬇️
types/src/account_state.rs 63.34% <0.00%> (-3.33%) ⬇️
commons/service-registry/src/service_actor.rs 38.71% <0.00%> (-3.22%) ⬇️
commons/accumulator/src/tree.rs 51.24% <0.00%> (-2.95%) ⬇️
commons/service-registry/src/service_ref.rs 65.76% <0.00%> (-2.73%) ⬇️
miner/src/generate_block_event_pacemaker.rs 41.87% <0.00%> (-2.32%) ⬇️
... and 59 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d55f96...17f6d55. Read the comment docs.

@jolestar jolestar enabled auto-merge (squash) June 14, 2022 07:48
Copy link
Member

@jolestar jolestar left a comment

Choose a reason for hiding this comment

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

LGTM

@jolestar jolestar merged commit 1553c35 into starcoinorg:master Jun 14, 2022
@coldnight coldnight deleted the feat-resolve-module-function-index branch June 14, 2022 10:01
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.

[Feature Request] Explain the ExecutionFailure transaction status
2 participants