{"action":"created","comment":{"url":"https://api.github.com/repos/ethcore/parity/pulls/comments/81721693","pull_request_review_id":2679951,"id":81721693,"diff_hunk":"@@ -39,41 +39,97 @@ pub struct ApplyOutcome {\n pub type ApplyResult = Result<ApplyOutcome, Error>;\n \n #[derive(Debug)]\n-enum AccountEntry {\n+enum AccountData {\n \t/// Contains account data.\n \tCached(Account),\n \t/// Account has been deleted.\n-\tKilled,\n \t/// Account does not exist.\n \tMissing,\n }\n \n-impl AccountEntry {\n-\tfn is_dirty(&self) -> bool {\n+impl AccountData {\n+\t/// Clone dirty data into a new `AccountData`.\n+\tfn clone_dirty(&self) -> AccountData {\n \t\tmatch *self {\n-\t\t\tAccountEntry::Cached(ref a) => a.is_dirty(),\n-\t\t\tAccountEntry::Killed => true,\n-\t\t\tAccountEntry::Missing => false,\n+\t\t\tAccountData::Cached(ref acc) => AccountData::Cached(acc.clone_dirty()),\n+\t\t\tAccountData::Missing => AccountData::Missing,\n \t\t}\n \t}\n \n+\t/// Clone account entry data that needs to be saved in the snapshot.\n+\t/// This includes basic account information and all locally modified storage keys\n+\tfn clone_for_snapshot(&self) -> AccountData {\n+\t\tmatch *self {\n+\t\t\tAccountData::Cached(ref acc) => AccountData::Cached(acc.clone_dirty()),\n+\t\t\tAccountData::Missing => AccountData::Missing,\n+\t\t}\n+\t}\n+}\n+\n+#[derive(Eq, PartialEq, Clone, Copy, Debug)]\n+enum AccountState {\n+\tClean,\n+\tDirty,\n+\tCommited,\n+}\n+\n+#[derive(Debug)]\n+struct AccountEntry {\n+\taccount: AccountData,\n+\tstate: AccountState,\n+}\n+\n+impl AccountEntry {\n+\tfn is_dirty(&self) -> bool {\n+\t\tself.state == AccountState::Dirty\n+\t}\n+\n \t/// Clone dirty data into new `AccountEntry`.\n \t/// Returns None if clean.\n \tfn clone_dirty(&self) -> Option<AccountEntry> {\n-\t\tmatch *self {\n-\t\t\tAccountEntry::Cached(ref acc) if acc.is_dirty() => Some(AccountEntry::Cached(acc.clone_dirty())),\n-\t\t\tAccountEntry::Killed => Some(AccountEntry::Killed),\n-\t\t\t_ => None,\n+\t\tmatch self.is_dirty() {\n+\t\t\ttrue => Some( AccountEntry {\n+\t\t\t\taccount: self.account.clone_dirty(),\n+\t\t\t\tstate: self.state,\n+\t\t\t}),\n+\t\t\tfalse => None,\n \t\t}\n \t}\n \n \t/// Clone account entry data that needs to be saved in the snapshot.\n \t/// This includes basic account information and all locally cached storage keys\n \tfn clone_for_snapshot(&self) -> AccountEntry {\n-\t\tmatch *self {\n-\t\t\tAccountEntry::Cached(ref acc) => AccountEntry::Cached(acc.clone_all()),\n-\t\t\tAccountEntry::Killed => AccountEntry::Killed,\n-\t\t\tAccountEntry::Missing => AccountEntry::Missing,\n+\t\tAccountEntry {\n+\t\t\taccount: self.account.clone_for_snapshot(),\n+\t\t\tstate: self.state,\n+\t\t}\n+\t}\n+\n+\tfn new_dirty(account: AccountData) -> AccountEntry {\n+\t\tAccountEntry {\n+\t\t\taccount: account,\n+\t\t\tstate: AccountState::Dirty,\n+\t\t}\n+\t}\n+\t\n+\tfn new_clean(account: AccountData) -> AccountEntry {\n+\t\tAccountEntry {\n+\t\t\taccount: account,\n+\t\t\tstate: AccountState::Clean,\n+\t\t}\n+\t}\n+\n+\tfn merge_snapshot(&mut self, other: AccountEntry) {\n+\t\tself.state = other.state;\n+\t\tmatch other.account {\n+\t\t\tAccountData::Missing => self.account = AccountData::Missing,\n+\t\t\tAccountData::Cached(acc) => match self.account {\n+\t\t\t\tAccountData::Cached(ref mut ours) => {\n+\t\t\t\t\tours.revert_storage_changes();\n+\t\t\t\t\tours.merge_with(acc);","path":"ethcore/src/state.rs","position":115,"original_position":115,"commit_id":"7c4c72935205f9c32dbbdc0fef27c63973ce4def","original_commit_id":"7c4c72935205f9c32dbbdc0fef27c63973ce4def","user":{"login":"arkpar","id":9008569,"avatar_url":"https://avatars.githubusercontent.com/u/9008569?v=3","gravatar_id":"","url":"https://api.github.com/users/arkpar","html_url":"https://github.com/arkpar","followers_url":"https://api.github.com/users/arkpar/followers","following_url":"https://api.github.com/users/arkpar/following{/other_user}","gists_url":"https://api.github.com/users/arkpar/gists{/gist_id}","starred_url":"https://api.github.com/users/arkpar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arkpar/subscriptions","organizations_url":"https://api.github.com/users/arkpar/orgs","repos_url":"https://api.github.com/users/arkpar/repos","events_url":"https://api.github.com/users/arkpar/events{/privacy}","received_events_url":"https://api.github.com/users/arkpar/received_events","type":"User","site_admin":false},"body":"When reverting changes from a snapshot it makes sense to keep cached storage around and discard modified data.","created_at":"2016-10-04T09:49:30Z","updated_at":"2016-10-04T09:49:30Z","html_url":"https://github.com/ethcore/parity/pull/2438#discussion_r81721693","pull_request_url":"https://api.github.com/repos/ethcore/parity/pulls/2438","_links":{"self":{"href":"https://api.github.com/repos/ethcore/parity/pulls/comments/81721693"},"html":{"href":"https://github.com/ethcore/parity/pull/2438#discussion_r81721693"},"pull_request":{"href":"https://api.github.com/repos/ethcore/parity/pulls/2438"}}},"pull_request":{"url":"https://api.github.com/repos/ethcore/parity/pulls/2438","id":87719801,"html_url":"https://github.com/ethcore/parity/pull/2438","diff_url":"https://github.com/ethcore/parity/pull/2438.diff","patch_url":"https://github.com/ethcore/parity/pull/2438.patch","issue_url":"https://api.github.com/repos/ethcore/parity/issues/2438","number":2438,"state":"open","locked":false,"title":"Caching optimizations","user":{"login":"arkpar","id":9008569,"avatar_url":"https://avatars.githubusercontent.com/u/9008569?v=3","gravatar_id":"","url":"https://api.github.com/users/arkpar","html_url":"https://github.com/arkpar","followers_url":"https://api.github.com/users/arkpar/followers","following_url":"https://api.github.com/users/arkpar/following{/other_user}","gists_url":"https://api.github.com/users/arkpar/gists{/gist_id}","starred_url":"https://api.github.com/users/arkpar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arkpar/subscriptions","organizations_url":"https://api.github.com/users/arkpar/orgs","repos_url":"https://api.github.com/users/arkpar/repos","events_url":"https://api.github.com/users/arkpar/events{/privacy}","received_events_url":"https://api.github.com/users/arkpar/received_events","type":"User","site_admin":false},"body":"* Canonical state can handle block reorganizations. If a block is retracted all the accounts that were modified in it are removed from cache.\r\n* State has been changed to track everything that has been modified\r\n* State snapshot optimization to keep storage cache around","created_at":"2016-10-03T13:50:33Z","updated_at":"2016-10-04T09:49:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b540632d386e156f57708b72910463686b22b52","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ethcore/parity/pulls/2438/commits","review_comments_url":"https://api.github.com/repos/ethcore/parity/pulls/2438/comments","review_comment_url":"https://api.github.com/repos/ethcore/parity/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ethcore/parity/issues/2438/comments","statuses_url":"https://api.github.com/repos/ethcore/parity/statuses/7c4c72935205f9c32dbbdc0fef27c63973ce4def","head":{"label":"ethcore:beta-cache-opt","ref":"beta-cache-opt","sha":"7c4c72935205f9c32dbbdc0fef27c63973ce4def","user":{"login":"ethcore","id":14176906,"avatar_url":"https://avatars.githubusercontent.com/u/14176906?v=3","gravatar_id":"","url":"https://api.github.com/users/ethcore","html_url":"https://github.com/ethcore","followers_url":"https://api.github.com/users/ethcore/followers","following_url":"https://api.github.com/users/ethcore/following{/other_user}","gists_url":"https://api.github.com/users/ethcore/gists{/gist_id}","starred_url":"https://api.github.com/users/ethcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethcore/subscriptions","organizations_url":"https://api.github.com/users/ethcore/orgs","repos_url":"https://api.github.com/users/ethcore/repos","events_url":"https://api.github.com/users/ethcore/events{/privacy}","received_events_url":"https://api.github.com/users/ethcore/received_events","type":"Organization","site_admin":false},"repo":{"id":46714939,"name":"parity","full_name":"ethcore/parity","owner":{"login":"ethcore","id":14176906,"avatar_url":"https://avatars.githubusercontent.com/u/14176906?v=3","gravatar_id":"","url":"https://api.github.com/users/ethcore","html_url":"https://github.com/ethcore","followers_url":"https://api.github.com/users/ethcore/followers","following_url":"https://api.github.com/users/ethcore/following{/other_user}","gists_url":"https://api.github.com/users/ethcore/gists{/gist_id}","starred_url":"https://api.github.com/users/ethcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethcore/subscriptions","organizations_url":"https://api.github.com/users/ethcore/orgs","repos_url":"https://api.github.com/users/ethcore/repos","events_url":"https://api.github.com/users/ethcore/events{/privacy}","received_events_url":"https://api.github.com/users/ethcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ethcore/parity","description":"Fast, light, robust Ethereum implementation","fork":false,"url":"https://api.github.com/repos/ethcore/parity","forks_url":"https://api.github.com/repos/ethcore/parity/forks","keys_url":"https://api.github.com/repos/ethcore/parity/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ethcore/parity/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ethcore/parity/teams","hooks_url":"https://api.github.com/repos/ethcore/parity/hooks","issue_events_url":"https://api.github.com/repos/ethcore/parity/issues/events{/number}","events_url":"https://api.github.com/repos/ethcore/parity/events","assignees_url":"https://api.github.com/repos/ethcore/parity/assignees{/user}","branches_url":"https://api.github.com/repos/ethcore/parity/branches{/branch}","tags_url":"https://api.github.com/repos/ethcore/parity/tags","blobs_url":"https://api.github.com/repos/ethcore/parity/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ethcore/parity/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ethcore/parity/git/refs{/sha}","trees_url":"https://api.github.com/repos/ethcore/parity/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ethcore/parity/statuses/{sha}","languages_url":"https://api.github.com/repos/ethcore/parity/languages","stargazers_url":"https://api.github.com/repos/ethcore/parity/stargazers","contributors_url":"https://api.github.com/repos/ethcore/parity/contributors","subscribers_url":"https://api.github.com/repos/ethcore/parity/subscribers","subscription_url":"https://api.github.com/repos/ethcore/parity/subscription","commits_url":"https://api.github.com/repos/ethcore/parity/commits{/sha}","git_commits_url":"https://api.github.com/repos/ethcore/parity/git/commits{/sha}","comments_url":"https://api.github.com/repos/ethcore/parity/comments{/number}","issue_comment_url":"https://api.github.com/repos/ethcore/parity/issues/comments{/number}","contents_url":"https://api.github.com/repos/ethcore/parity/contents/{+path}","compare_url":"https://api.github.com/repos/ethcore/parity/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ethcore/parity/merges","archive_url":"https://api.github.com/repos/ethcore/parity/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ethcore/parity/downloads","issues_url":"https://api.github.com/repos/ethcore/parity/issues{/number}","pulls_url":"https://api.github.com/repos/ethcore/parity/pulls{/number}","milestones_url":"https://api.github.com/repos/ethcore/parity/milestones{/number}","notifications_url":"https://api.github.com/repos/ethcore/parity/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ethcore/parity/labels{/name}","releases_url":"https://api.github.com/repos/ethcore/parity/releases{/id}","deployments_url":"https://api.github.com/repos/ethcore/parity/deployments","created_at":"2015-11-23T11:07:32Z","updated_at":"2016-10-04T06:51:41Z","pushed_at":"2016-10-04T09:43:33Z","git_url":"git://github.com/ethcore/parity.git","ssh_url":"git@github.com:ethcore/parity.git","clone_url":"https://github.com/ethcore/parity.git","svn_url":"https://github.com/ethcore/parity","homepage":"","size":42871,"stargazers_count":571,"watchers_count":571,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":104,"mirror_url":null,"open_issues_count":195,"forks":104,"open_issues":195,"watchers":571,"default_branch":"master"}},"base":{"label":"ethcore:beta","ref":"beta","sha":"df4d98001ae5ac9fb162ac9fe7a22c7c3cebc95d","user":{"login":"ethcore","id":14176906,"avatar_url":"https://avatars.githubusercontent.com/u/14176906?v=3","gravatar_id":"","url":"https://api.github.com/users/ethcore","html_url":"https://github.com/ethcore","followers_url":"https://api.github.com/users/ethcore/followers","following_url":"https://api.github.com/users/ethcore/following{/other_user}","gists_url":"https://api.github.com/users/ethcore/gists{/gist_id}","starred_url":"https://api.github.com/users/ethcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethcore/subscriptions","organizations_url":"https://api.github.com/users/ethcore/orgs","repos_url":"https://api.github.com/users/ethcore/repos","events_url":"https://api.github.com/users/ethcore/events{/privacy}","received_events_url":"https://api.github.com/users/ethcore/received_events","type":"Organization","site_admin":false},"repo":{"id":46714939,"name":"parity","full_name":"ethcore/parity","owner":{"login":"ethcore","id":14176906,"avatar_url":"https://avatars.githubusercontent.com/u/14176906?v=3","gravatar_id":"","url":"https://api.github.com/users/ethcore","html_url":"https://github.com/ethcore","followers_url":"https://api.github.com/users/ethcore/followers","following_url":"https://api.github.com/users/ethcore/following{/other_user}","gists_url":"https://api.github.com/users/ethcore/gists{/gist_id}","starred_url":"https://api.github.com/users/ethcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethcore/subscriptions","organizations_url":"https://api.github.com/users/ethcore/orgs","repos_url":"https://api.github.com/users/ethcore/repos","events_url":"https://api.github.com/users/ethcore/events{/privacy}","received_events_url":"https://api.github.com/users/ethcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ethcore/parity","description":"Fast, light, robust Ethereum implementation","fork":false,"url":"https://api.github.com/repos/ethcore/parity","forks_url":"https://api.github.com/repos/ethcore/parity/forks","keys_url":"https://api.github.com/repos/ethcore/parity/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ethcore/parity/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ethcore/parity/teams","hooks_url":"https://api.github.com/repos/ethcore/parity/hooks","issue_events_url":"https://api.github.com/repos/ethcore/parity/issues/events{/number}","events_url":"https://api.github.com/repos/ethcore/parity/events","assignees_url":"https://api.github.com/repos/ethcore/parity/assignees{/user}","branches_url":"https://api.github.com/repos/ethcore/parity/branches{/branch}","tags_url":"https://api.github.com/repos/ethcore/parity/tags","blobs_url":"https://api.github.com/repos/ethcore/parity/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ethcore/parity/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ethcore/parity/git/refs{/sha}","trees_url":"https://api.github.com/repos/ethcore/parity/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ethcore/parity/statuses/{sha}","languages_url":"https://api.github.com/repos/ethcore/parity/languages","stargazers_url":"https://api.github.com/repos/ethcore/parity/stargazers","contributors_url":"https://api.github.com/repos/ethcore/parity/contributors","subscribers_url":"https://api.github.com/repos/ethcore/parity/subscribers","subscription_url":"https://api.github.com/repos/ethcore/parity/subscription","commits_url":"https://api.github.com/repos/ethcore/parity/commits{/sha}","git_commits_url":"https://api.github.com/repos/ethcore/parity/git/commits{/sha}","comments_url":"https://api.github.com/repos/ethcore/parity/comments{/number}","issue_comment_url":"https://api.github.com/repos/ethcore/parity/issues/comments{/number}","contents_url":"https://api.github.com/repos/ethcore/parity/contents/{+path}","compare_url":"https://api.github.com/repos/ethcore/parity/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ethcore/parity/merges","archive_url":"https://api.github.com/repos/ethcore/parity/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ethcore/parity/downloads","issues_url":"https://api.github.com/repos/ethcore/parity/issues{/number}","pulls_url":"https://api.github.com/repos/ethcore/parity/pulls{/number}","milestones_url":"https://api.github.com/repos/ethcore/parity/milestones{/number}","notifications_url":"https://api.github.com/repos/ethcore/parity/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ethcore/parity/labels{/name}","releases_url":"https://api.github.com/repos/ethcore/parity/releases{/id}","deployments_url":"https://api.github.com/repos/ethcore/parity/deployments","created_at":"2015-11-23T11:07:32Z","updated_at":"2016-10-04T06:51:41Z","pushed_at":"2016-10-04T09:43:33Z","git_url":"git://github.com/ethcore/parity.git","ssh_url":"git@github.com:ethcore/parity.git","clone_url":"https://github.com/ethcore/parity.git","svn_url":"https://github.com/ethcore/parity","homepage":"","size":42871,"stargazers_count":571,"watchers_count":571,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":104,"mirror_url":null,"open_issues_count":195,"forks":104,"open_issues":195,"watchers":571,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ethcore/parity/pulls/2438"},"html":{"href":"https://github.com/ethcore/parity/pull/2438"},"issue":{"href":"https://api.github.com/repos/ethcore/parity/issues/2438"},"comments":{"href":"https://api.github.com/repos/ethcore/parity/issues/2438/comments"},"review_comments":{"href":"https://api.github.com/repos/ethcore/parity/pulls/2438/comments"},"review_comment":{"href":"https://api.github.com/repos/ethcore/parity/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ethcore/parity/pulls/2438/commits"},"statuses":{"href":"https://api.github.com/repos/ethcore/parity/statuses/7c4c72935205f9c32dbbdc0fef27c63973ce4def"}}}}
{"actor":{"display_login":"arkpar"}}