{"action":"created","comment":{"url":"https://api.github.com/repos/paritytech/polkadot/pulls/comments/203075793","pull_request_review_id":137895240,"id":203075793,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMzA3NTc5Mw==","diff_hunk":"@@ -0,0 +1,257 @@\n+// Copyright 2018 Parity Technologies (UK) Ltd.\n+// This file is part of Substrate.\n+\n+// Substrate is free software: you can redistribute it and/or modify\n+// it under the terms of the GNU General Public License as published by\n+// the Free Software Foundation, either version 3 of the License, or\n+// (at your option) any later version.\n+\n+// Substrate is distributed in the hope that it will be useful,\n+// but WITHOUT ANY WARRANTY; without even the implied warranty of\n+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+// GNU General Public License for more details.\n+\n+// You should have received a copy of the GNU General Public License\n+// along with Substrate. If not, see <http://www.gnu.org/licenses/>.\n+\n+use super::{CodeOf, ContractAddressFor, Module, Trait};\n+use account_db::{AccountDb, OverlayAccountDb};\n+use gas::GasMeter;\n+use vm;\n+\n+use rstd::prelude::*;\n+use runtime_primitives::traits::Zero;\n+use runtime_support::StorageMap;\n+use staking;\n+use system;\n+\n+pub struct CreateReceipt<T: Trait> {\n+\tpub address: T::AccountId,\n+}\n+\n+pub struct CallReceipt {\n+\tpub return_data: Vec<u8>,\n+}\n+\n+pub struct ExecutionContext<'a, T: Trait + 'a> {\n+\t// typically should be dest\n+\tpub self_account: T::AccountId,\n+\tpub overlay: OverlayAccountDb<'a, T>,\n+\tpub depth: usize,\n+}\n+\n+impl<'a, T: Trait> ExecutionContext<'a, T> {\n+\t/// Make a call to the specified address.\n+\tpub fn call(\n+\t\t&mut self,\n+\t\tcaller: T::AccountId,\n+\t\tdest: T::AccountId,\n+\t\tvalue: T::Balance,\n+\t\tgas_meter: &mut GasMeter<T>,\n+\t\t_data: Vec<u8>,\n+\t) -> Result<CallReceipt, &'static str> {\n+\t\tlet dest_code = <CodeOf<T>>::get(&dest);\n+\n+\t\t// TODO: check the new depth\n+\n+\t\tlet call_base_fee = <Module<T>>::call_base_fee();\n+\t\tif gas_meter.charge(call_base_fee).is_out_of_gas() {\n+\t\t\treturn Err(\"not enough gas to pay base call fee\");\n+\t\t}\n+\n+\t\tlet (exec_result, change_set) = {\n+\t\t\tlet mut overlay = OverlayAccountDb::new(&self.overlay);\n+\n+\t\t\tif value > T::Balance::zero() {\n+\t\t\t\ttransfer(\n+\t\t\t\t\tgas_meter,\n+\t\t\t\t\tfalse,\n+\t\t\t\t\t&self.self_account,\n+\t\t\t\t\t&dest,\n+\t\t\t\t\tvalue,\n+\t\t\t\t\t&mut overlay,\n+\t\t\t\t)?;\n+\t\t\t}\n+\n+\t\t\tlet mut nested = ExecutionContext {\n+\t\t\t\toverlay: overlay,\n+\t\t\t\tself_account: dest.clone(),\n+\t\t\t\tdepth: self.depth + 1,\n+\t\t\t};\n+\t\t\tlet exec_result = if !dest_code.is_empty() {\n+\t\t\t\tvm::execute(\n+\t\t\t\t\t&dest_code,\n+\t\t\t\t\t&mut CallContext {\n+\t\t\t\t\t\tctx: &mut nested,\n+\t\t\t\t\t\t_caller: caller,\n+\t\t\t\t\t},\n+\t\t\t\t\tgas_meter,\n+\t\t\t\t).map_err(|_| \"vm execute returned error while call\")?","path":"substrate/runtime/contract/src/exec.rs","position":89,"original_position":89,"commit_id":"4dfc7dcd04cd498a1f12644c2d9e80250ad2af37","original_commit_id":"4dfc7dcd04cd498a1f12644c2d9e80250ad2af37","user":{"login":"pepyakin","id":2205845,"node_id":"MDQ6VXNlcjIyMDU4NDU=","avatar_url":"https://avatars2.githubusercontent.com/u/2205845?v=4","gravatar_id":"","url":"https://api.github.com/users/pepyakin","html_url":"https://github.com/pepyakin","followers_url":"https://api.github.com/users/pepyakin/followers","following_url":"https://api.github.com/users/pepyakin/following{/other_user}","gists_url":"https://api.github.com/users/pepyakin/gists{/gist_id}","starred_url":"https://api.github.com/users/pepyakin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pepyakin/subscriptions","organizations_url":"https://api.github.com/users/pepyakin/orgs","repos_url":"https://api.github.com/users/pepyakin/repos","events_url":"https://api.github.com/users/pepyakin/events{/privacy}","received_events_url":"https://api.github.com/users/pepyakin/received_events","type":"User","site_admin":false},"body":"let's move this to [this thread](https://github.com/paritytech/polkadot/pull/345/files/4dfc7dcd04cd498a1f12644c2d9e80250ad2af37#r203018403)","created_at":"2018-07-17T15:46:24Z","updated_at":"2018-07-17T15:46:25Z","html_url":"https://github.com/paritytech/polkadot/pull/345#discussion_r203075793","pull_request_url":"https://api.github.com/repos/paritytech/polkadot/pulls/345","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/paritytech/polkadot/pulls/comments/203075793"},"html":{"href":"https://github.com/paritytech/polkadot/pull/345#discussion_r203075793"},"pull_request":{"href":"https://api.github.com/repos/paritytech/polkadot/pulls/345"}},"in_reply_to_id":203018765},"pull_request":{"url":"https://api.github.com/repos/paritytech/polkadot/pulls/345","id":201889789,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAxODg5Nzg5","html_url":"https://github.com/paritytech/polkadot/pull/345","diff_url":"https://github.com/paritytech/polkadot/pull/345.diff","patch_url":"https://github.com/paritytech/polkadot/pull/345.patch","issue_url":"https://api.github.com/repos/paritytech/polkadot/issues/345","number":345,"state":"open","locked":false,"title":"Make contract a separate runtime module","user":{"login":"pepyakin","id":2205845,"node_id":"MDQ6VXNlcjIyMDU4NDU=","avatar_url":"https://avatars2.githubusercontent.com/u/2205845?v=4","gravatar_id":"","url":"https://api.github.com/users/pepyakin","html_url":"https://github.com/pepyakin","followers_url":"https://api.github.com/users/pepyakin/followers","following_url":"https://api.github.com/users/pepyakin/following{/other_user}","gists_url":"https://api.github.com/users/pepyakin/gists{/gist_id}","starred_url":"https://api.github.com/users/pepyakin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pepyakin/subscriptions","organizations_url":"https://api.github.com/users/pepyakin/orgs","repos_url":"https://api.github.com/users/pepyakin/repos","events_url":"https://api.github.com/users/pepyakin/events{/privacy}","received_events_url":"https://api.github.com/users/pepyakin/received_events","type":"User","site_admin":false},"body":"The main theme of this PR is extracting contract module from staking module, and lifting it to a standalone module which has it's own entrypoints: `call` and `create`. \r\n\r\nNow, the module relations are inverted: now `contract` module uses `staking` module only for transfers. This is in contrast how it was before: `staking` invoked `contract` module whenever there is a code in account to which `transfer` is happening. This change allows us to avoid polluting `staking` module with contract concepts (such as gas limits, etc).\r\n\r\nThere are however a few complications:\r\n\r\n- Since plain transfers in `staking` can kill accounts, we need to provide a way for notifying other modules of such kills. For that reason `OnAccountKill` is added to `staking::Trait`.\r\n- Revertable state mechanisms are moved to the `contract` crate. However, we still need to have an ability to issue ephemeral (which can be reverted) transfers on the ephemeral storage. For that reason `effect_transfer`/`effect_create` logic is [duplicated](https://github.com/paritytech/polkadot/blob/a1ecfb03625076b13fd64d9100a0d157b1b1af05/substrate/runtime/contract/src/exec.rs#L192) in the contract module.\r\n\r\nAlong with that numerous changes were made, such as:\r\n\r\n- [Constructors and returning data](https://github.com/paritytech/polkadot/pull/253) were re-applied\r\n- Nested calls support with gas propogation was added\r\n- Additional fees per call and create were introduced\r\n\r\nHowever, I would say there are still areas to improve, including:\r\n\r\n- implementing remaining futures to MVP\r\n- avoiding quadratic attacks\r\n- limiting maximal depth of the transaction stack\r\n- refactoring of gas mechanism\r\n- more convenient ways of testing the runtime\r\n- way more tests\r\n- more informative errors which e.g preserves transaction call stacks for ease of debugging.\r\n- etc\r\n\r\nI'm planning to address these issues in the following PRs. This PR already got pretty big.","created_at":"2018-07-17T10:09:28Z","updated_at":"2018-07-17T15:46:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"930dfce25811771a66428148cacab10f8434bb84","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":746560607,"node_id":"MDU6TGFiZWw3NDY1NjA2MDc=","url":"https://api.github.com/repos/paritytech/polkadot/labels/A0-pleasereview","name":"A0-pleasereview","color":"666666","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/paritytech/polkadot/pulls/345/commits","review_comments_url":"https://api.github.com/repos/paritytech/polkadot/pulls/345/comments","review_comment_url":"https://api.github.com/repos/paritytech/polkadot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paritytech/polkadot/issues/345/comments","statuses_url":"https://api.github.com/repos/paritytech/polkadot/statuses/4dfc7dcd04cd498a1f12644c2d9e80250ad2af37","head":{"label":"paritytech:ser-contract-ioc","ref":"ser-contract-ioc","sha":"4dfc7dcd04cd498a1f12644c2d9e80250ad2af37","user":{"login":"paritytech","id":14176906,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTc2OTA2","avatar_url":"https://avatars2.githubusercontent.com/u/14176906?v=4","gravatar_id":"","url":"https://api.github.com/users/paritytech","html_url":"https://github.com/paritytech","followers_url":"https://api.github.com/users/paritytech/followers","following_url":"https://api.github.com/users/paritytech/following{/other_user}","gists_url":"https://api.github.com/users/paritytech/gists{/gist_id}","starred_url":"https://api.github.com/users/paritytech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paritytech/subscriptions","organizations_url":"https://api.github.com/users/paritytech/orgs","repos_url":"https://api.github.com/users/paritytech/repos","events_url":"https://api.github.com/users/paritytech/events{/privacy}","received_events_url":"https://api.github.com/users/paritytech/received_events","type":"Organization","site_admin":false},"repo":{"id":109872620,"node_id":"MDEwOlJlcG9zaXRvcnkxMDk4NzI2MjA=","name":"polkadot","full_name":"paritytech/polkadot","owner":{"login":"paritytech","id":14176906,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTc2OTA2","avatar_url":"https://avatars2.githubusercontent.com/u/14176906?v=4","gravatar_id":"","url":"https://api.github.com/users/paritytech","html_url":"https://github.com/paritytech","followers_url":"https://api.github.com/users/paritytech/followers","following_url":"https://api.github.com/users/paritytech/following{/other_user}","gists_url":"https://api.github.com/users/paritytech/gists{/gist_id}","starred_url":"https://api.github.com/users/paritytech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paritytech/subscriptions","organizations_url":"https://api.github.com/users/paritytech/orgs","repos_url":"https://api.github.com/users/paritytech/repos","events_url":"https://api.github.com/users/paritytech/events{/privacy}","received_events_url":"https://api.github.com/users/paritytech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paritytech/polkadot","description":"Polkadot Node Implementation","fork":false,"url":"https://api.github.com/repos/paritytech/polkadot","forks_url":"https://api.github.com/repos/paritytech/polkadot/forks","keys_url":"https://api.github.com/repos/paritytech/polkadot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paritytech/polkadot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paritytech/polkadot/teams","hooks_url":"https://api.github.com/repos/paritytech/polkadot/hooks","issue_events_url":"https://api.github.com/repos/paritytech/polkadot/issues/events{/number}","events_url":"https://api.github.com/repos/paritytech/polkadot/events","assignees_url":"https://api.github.com/repos/paritytech/polkadot/assignees{/user}","branches_url":"https://api.github.com/repos/paritytech/polkadot/branches{/branch}","tags_url":"https://api.github.com/repos/paritytech/polkadot/tags","blobs_url":"https://api.github.com/repos/paritytech/polkadot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paritytech/polkadot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paritytech/polkadot/git/refs{/sha}","trees_url":"https://api.github.com/repos/paritytech/polkadot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paritytech/polkadot/statuses/{sha}","languages_url":"https://api.github.com/repos/paritytech/polkadot/languages","stargazers_url":"https://api.github.com/repos/paritytech/polkadot/stargazers","contributors_url":"https://api.github.com/repos/paritytech/polkadot/contributors","subscribers_url":"https://api.github.com/repos/paritytech/polkadot/subscribers","subscription_url":"https://api.github.com/repos/paritytech/polkadot/subscription","commits_url":"https://api.github.com/repos/paritytech/polkadot/commits{/sha}","git_commits_url":"https://api.github.com/repos/paritytech/polkadot/git/commits{/sha}","comments_url":"https://api.github.com/repos/paritytech/polkadot/comments{/number}","issue_comment_url":"https://api.github.com/repos/paritytech/polkadot/issues/comments{/number}","contents_url":"https://api.github.com/repos/paritytech/polkadot/contents/{+path}","compare_url":"https://api.github.com/repos/paritytech/polkadot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paritytech/polkadot/merges","archive_url":"https://api.github.com/repos/paritytech/polkadot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paritytech/polkadot/downloads","issues_url":"https://api.github.com/repos/paritytech/polkadot/issues{/number}","pulls_url":"https://api.github.com/repos/paritytech/polkadot/pulls{/number}","milestones_url":"https://api.github.com/repos/paritytech/polkadot/milestones{/number}","notifications_url":"https://api.github.com/repos/paritytech/polkadot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paritytech/polkadot/labels{/name}","releases_url":"https://api.github.com/repos/paritytech/polkadot/releases{/id}","deployments_url":"https://api.github.com/repos/paritytech/polkadot/deployments","created_at":"2017-11-07T18:08:53Z","updated_at":"2018-07-17T15:14:09Z","pushed_at":"2018-07-17T15:42:49Z","git_url":"git://github.com/paritytech/polkadot.git","ssh_url":"git@github.com:paritytech/polkadot.git","clone_url":"https://github.com/paritytech/polkadot.git","svn_url":"https://github.com/paritytech/polkadot","homepage":null,"size":29847,"stargazers_count":276,"watchers_count":276,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":54,"mirror_url":null,"archived":false,"open_issues_count":56,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":54,"open_issues":56,"watchers":276,"default_branch":"master"}},"base":{"label":"paritytech:master","ref":"master","sha":"8fd997f101390f8fc1238b1f799db6a2d5ebe97c","user":{"login":"paritytech","id":14176906,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTc2OTA2","avatar_url":"https://avatars2.githubusercontent.com/u/14176906?v=4","gravatar_id":"","url":"https://api.github.com/users/paritytech","html_url":"https://github.com/paritytech","followers_url":"https://api.github.com/users/paritytech/followers","following_url":"https://api.github.com/users/paritytech/following{/other_user}","gists_url":"https://api.github.com/users/paritytech/gists{/gist_id}","starred_url":"https://api.github.com/users/paritytech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paritytech/subscriptions","organizations_url":"https://api.github.com/users/paritytech/orgs","repos_url":"https://api.github.com/users/paritytech/repos","events_url":"https://api.github.com/users/paritytech/events{/privacy}","received_events_url":"https://api.github.com/users/paritytech/received_events","type":"Organization","site_admin":false},"repo":{"id":109872620,"node_id":"MDEwOlJlcG9zaXRvcnkxMDk4NzI2MjA=","name":"polkadot","full_name":"paritytech/polkadot","owner":{"login":"paritytech","id":14176906,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0MTc2OTA2","avatar_url":"https://avatars2.githubusercontent.com/u/14176906?v=4","gravatar_id":"","url":"https://api.github.com/users/paritytech","html_url":"https://github.com/paritytech","followers_url":"https://api.github.com/users/paritytech/followers","following_url":"https://api.github.com/users/paritytech/following{/other_user}","gists_url":"https://api.github.com/users/paritytech/gists{/gist_id}","starred_url":"https://api.github.com/users/paritytech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paritytech/subscriptions","organizations_url":"https://api.github.com/users/paritytech/orgs","repos_url":"https://api.github.com/users/paritytech/repos","events_url":"https://api.github.com/users/paritytech/events{/privacy}","received_events_url":"https://api.github.com/users/paritytech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paritytech/polkadot","description":"Polkadot Node Implementation","fork":false,"url":"https://api.github.com/repos/paritytech/polkadot","forks_url":"https://api.github.com/repos/paritytech/polkadot/forks","keys_url":"https://api.github.com/repos/paritytech/polkadot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paritytech/polkadot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paritytech/polkadot/teams","hooks_url":"https://api.github.com/repos/paritytech/polkadot/hooks","issue_events_url":"https://api.github.com/repos/paritytech/polkadot/issues/events{/number}","events_url":"https://api.github.com/repos/paritytech/polkadot/events","assignees_url":"https://api.github.com/repos/paritytech/polkadot/assignees{/user}","branches_url":"https://api.github.com/repos/paritytech/polkadot/branches{/branch}","tags_url":"https://api.github.com/repos/paritytech/polkadot/tags","blobs_url":"https://api.github.com/repos/paritytech/polkadot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paritytech/polkadot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paritytech/polkadot/git/refs{/sha}","trees_url":"https://api.github.com/repos/paritytech/polkadot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paritytech/polkadot/statuses/{sha}","languages_url":"https://api.github.com/repos/paritytech/polkadot/languages","stargazers_url":"https://api.github.com/repos/paritytech/polkadot/stargazers","contributors_url":"https://api.github.com/repos/paritytech/polkadot/contributors","subscribers_url":"https://api.github.com/repos/paritytech/polkadot/subscribers","subscription_url":"https://api.github.com/repos/paritytech/polkadot/subscription","commits_url":"https://api.github.com/repos/paritytech/polkadot/commits{/sha}","git_commits_url":"https://api.github.com/repos/paritytech/polkadot/git/commits{/sha}","comments_url":"https://api.github.com/repos/paritytech/polkadot/comments{/number}","issue_comment_url":"https://api.github.com/repos/paritytech/polkadot/issues/comments{/number}","contents_url":"https://api.github.com/repos/paritytech/polkadot/contents/{+path}","compare_url":"https://api.github.com/repos/paritytech/polkadot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paritytech/polkadot/merges","archive_url":"https://api.github.com/repos/paritytech/polkadot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paritytech/polkadot/downloads","issues_url":"https://api.github.com/repos/paritytech/polkadot/issues{/number}","pulls_url":"https://api.github.com/repos/paritytech/polkadot/pulls{/number}","milestones_url":"https://api.github.com/repos/paritytech/polkadot/milestones{/number}","notifications_url":"https://api.github.com/repos/paritytech/polkadot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paritytech/polkadot/labels{/name}","releases_url":"https://api.github.com/repos/paritytech/polkadot/releases{/id}","deployments_url":"https://api.github.com/repos/paritytech/polkadot/deployments","created_at":"2017-11-07T18:08:53Z","updated_at":"2018-07-17T15:14:09Z","pushed_at":"2018-07-17T15:42:49Z","git_url":"git://github.com/paritytech/polkadot.git","ssh_url":"git@github.com:paritytech/polkadot.git","clone_url":"https://github.com/paritytech/polkadot.git","svn_url":"https://github.com/paritytech/polkadot","homepage":null,"size":29847,"stargazers_count":276,"watchers_count":276,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":54,"mirror_url":null,"archived":false,"open_issues_count":56,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":54,"open_issues":56,"watchers":276,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/paritytech/polkadot/pulls/345"},"html":{"href":"https://github.com/paritytech/polkadot/pull/345"},"issue":{"href":"https://api.github.com/repos/paritytech/polkadot/issues/345"},"comments":{"href":"https://api.github.com/repos/paritytech/polkadot/issues/345/comments"},"review_comments":{"href":"https://api.github.com/repos/paritytech/polkadot/pulls/345/comments"},"review_comment":{"href":"https://api.github.com/repos/paritytech/polkadot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paritytech/polkadot/pulls/345/commits"},"statuses":{"href":"https://api.github.com/repos/paritytech/polkadot/statuses/4dfc7dcd04cd498a1f12644c2d9e80250ad2af37"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"pepyakin"}}