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

Add invoke_system_call #813

Merged
merged 7 commits into from
Mar 7, 2023
Merged

Add invoke_system_call #813

merged 7 commits into from
Mar 7, 2023

Conversation

youkaicountry
Copy link
Contributor

@youkaicountry youkaicountry commented Feb 27, 2023

Resolves #799

Brief description

Add invoke_system_call

Checklist

  • I have built this pull request locally
  • I have ran the unit tests locally
  • I have manually tested this pull request
  • I have reviewed my pull request
  • I have added any relevant tests

Demonstration

Invoking system call get_contract_address, using the name koin

curl -d '{"jsonrpc":"2.0", "method":"chain.invoke_system_call", "params":{"id":10001, "args":"CgRrb2lu"}, "id":0}' http://localhost:8080/ | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   208  100    90  100   118  45000  59000 --:--:-- --:--:-- --:--:--  101k
{
  "jsonrpc": "2.0",
  "result": {
    "value": "Ch0KGwoZAC4z_RqpB7IkzpzmyUIokB0oOgLalW2nkQ=="
  },
  "id": 0
}

This protobuf message is a result object containing the proper address.

Here is invoking it using the name of the system call:

curl -d '{"jsonrpc":"2.0", "method":"chain.invoke_system_call", "params":{"name":"get_contract_address", "args":"CgRrb2lu"}, "id":0}' http://localhost:8080/ | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   213  100    90  100   123  45000  61500 --:--:-- --:--:-- --:--:--  104k
{
  "jsonrpc": "2.0",
  "result": {
    "value": "Ch0KGwoZAC4z_RqpB7IkzpzmyUIokB0oOgLalW2nkQ=="
  },
  "id": 0
}

and invoking get_resource_limits via id, then name:

curl -d '{"jsonrpc":"2.0", "method":"chain.invoke_system_call", "params":{"name":"get_resource_limits"}, "id":0}' http://localhost:8080/ | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   185  100    82  100   103  41000  51500 --:--:-- --:--:-- --:--:-- 92500
{
  "jsonrpc": "2.0",
  "result": {
    "value": "ChkKFwiAgCAQkrABGICAQCDUGijgzYuJATAR"
  },
  "id": 0
}


curl -d '{"jsonrpc":"2.0", "method":"chain.invoke_system_call", "params":{"id":203}, "id":0}' http://localhost:8080/ | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   165  100    82  100    83  27333  27666 --:--:-- --:--:-- --:--:-- 55000
{
  "jsonrpc": "2.0",
  "result": {
    "value": "ChkKFwiAgCAQkrABGICAQCDUGijgzYuJATAR"
  },
  "id": 0
}

Invoking with no name or id:

 curl -d '{"jsonrpc":"2.0", "method":"chain.invoke_system_call", "params":{}, "id":0}' http://localhost:8080/ | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   191  100   116  100    75   113k  75000 --:--:-- --:--:-- --:--:--  186k
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32603,
    "message": "Missing system call id or name",
    "data": "{\"code\":-103}"
  },
  "id": 0
}

Copy link
Member

@sgerbino sgerbino left a comment

Choose a reason for hiding this comment

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

TODO:

  • Create a PR for the koinos/koinos-proto changes
  • After merge of the koinos/koinos-proto PR, hook this branch up to master
  • Provide a manual test of the name_service contract calling get_address on koin
  • Provide a manual test of a genesis system call such as get_resource_limits

@sgerbino
Copy link
Member

sgerbino commented Mar 6, 2023

Do we need to handle the case where no ID or name is provided?

@sgerbino sgerbino merged commit 044a367 into master Mar 7, 2023
@sgerbino sgerbino deleted the 799-system-rpc branch March 7, 2023 17:17
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]: Provide a generic means to invoke system calls through RPC
2 participants