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(rpc): rpc query contract code deployed #3714

Merged
merged 11 commits into from
Dec 17, 2020
Merged

feat(rpc): rpc query contract code deployed #3714

merged 11 commits into from
Dec 17, 2020

Conversation

ailisp
Copy link
Member

@ailisp ailisp commented Dec 8, 2020

Address #1712,
also, add a dump_code command to state-viewer, so we can dump wasm file given account id, from node that doesn't yet have this rpc, e.g. testnet/mainnet:

nearcore (query-view-code) target/debug/state-viewer dump_code --account 1.test.near
Dec 08 17:48:01.772  INFO near: Opening store database at "/home/bo/.near/data"    
Dec 08 17:48:01.911  INFO runtime: Tracking shards: {}    
Dump contract of account 1.test.near into file output.wasm
nearcore (query-view-code) ls
ATTRIBUTIONS.md     CODEOWNERS         Dockerfile          METRICS.md   runtime         tests
Cargo.lock          config3601.json    Dockerfile.nightly  neard        rustfmt.toml    test-utils
Cargo.toml          configmaster.json  docs                nightly      rust-toolchain  tools
chain               CONTRIBUTING.md    genesis-tools       output.wasm  scripts         utils
codecov.yml         core               LICENSE             pytest       SECURITY.md
CODE_OF_CONDUCT.md  deny.toml          Makefile            README.md    target
nearcore (query-view-code) base64 < output.wasm 
47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=

Test Plan

~ http post http://localhost:3030 jsonrpc=2.0 id=dontcare method=query params:='{"request_type":"view_code","finality":"final","account_id":"test.near"}'
HTTP/1.1 200 OK
content-length: 155
content-type: application/json
date: Tue, 08 Dec 2020 23:05:36 GMT

{
    "error": {
        "code": -32000,
        "data": "contract code of account test.near does not exist while viewing",
        "message": "Server error"
    },
    "id": "dontcare",
    "jsonrpc": "2.0"
}

~ http post http://localhost:3030 jsonrpc=2.0 id=dontcare method=query params:='{"request_type":"view_code","finality":"final","account_id":"1.test.near"}'
HTTP/1.1 200 OK
content-length: 240
content-type: application/json
date: Tue, 08 Dec 2020 23:05:43 GMT

{
    "id": "dontcare",
    "jsonrpc": "2.0",
    "result": {
        "block_hash": "3mZUK6DnPUnGSKr7LdU56pNRd2vuMCsnWQQpP1qMFXnH",
        "block_height": 41020,
        "code_base64": "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
        "hash": "7KoFshMQkdyo5iTx8P2LbLu9jQpxRn24d27FrKShNVXs"
    }
}

and also nightly ci test_upload_contract_testnet

core/primitives/src/contract.rs Outdated Show resolved Hide resolved
test-utils/testlib/src/user/runtime_user.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

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

Can we add a sanity test to make sure that it works? Also this query maybe expensive if the contract code is large @frol

Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

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

LGTM! I left a few nits which you may ignore and merge as is, I only want us to be on the same page in terms of the reasoning we apply to the order of enum variants and From impls.

core/primitives/src/views.rs Outdated Show resolved Hide resolved
core/primitives/src/views.rs Outdated Show resolved Hide resolved
@frol
Copy link
Collaborator

frol commented Dec 11, 2020

Also this query maybe expensive if the contract code is large

I expect it to be on par with serving static files over HTTP (like Nginx does), which is usually bound by the network bandwidth rather than by the trie lookup, disk read, or memory read (borsh deserialization). Thus, I don't expect it to be more expensive than view_account query.

@ailisp
Copy link
Member Author

ailisp commented Dec 11, 2020

@evgenykuzyakov can you review to unblock this PR?

@frol frol merged commit e48d7a7 into master Dec 17, 2020
@frol frol deleted the query-view-code branch December 17, 2020 18:57
@mikedotexe
Copy link

mikedotexe commented Jan 11, 2021

Let's please let @thisisjoshford know when we add new routes/endpoints so we can update the docs :)

@frol
Copy link
Collaborator

frol commented Jan 11, 2021

@mikedotexe I even submitted a PR: near/docs#562 😄

@mikedotexe
Copy link

@mikedotexe I even submitted a PR: near/docs#562 😄

My man! Thanks, Frol, on top of things as always. I searched for "view_code" in the Issues and didn't see it. I'll close mine. Thanks!

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.

5 participants