{"action":"created","comment":{"url":"https://api.github.com/repos/ChainSafe/gossamer/pulls/comments/339219222","pull_request_review_id":307286137,"id":339219222,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMzOTIxOTIyMg==","diff_hunk":"@@ -185,6 +187,127 @@ func (l *leaf) Encode() ([]byte, error) {\n \treturn encoding, nil\n }\n \n+func Decode(r io.Reader) (node, error) {\n+\theader, err := readByte(r)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tnodeType := header >> 6\n+\tif nodeType == 1 {\n+\t\tl := new(leaf)\n+\t\terr := l.Decode(r, header)\n+\t\treturn l, err\n+\t} else if nodeType == 2 || nodeType == 3 {\n+\t\tb := new(branch)\n+\t\terr := b.Decode(r, header)\n+\t\treturn b, err\n+\t}\n+\n+\treturn nil, errors.New(\"cannot decode invalid encoding into node\")\n+}\n+\n+// Decode decodes a byte array with the following format into a branch node\n+// NodeHeader | Extra partial key length | Partial Key | Value\n+// where NodeHeader is a byte:\n+// most significant two bits of first byte: 10 if branch w/o value, 11 if branch w/ value\n+// least significant six bits of first byte: if len(key) > 62, 0x3f, otherwise len(key)\n+// where Extra partial key length is included if len(key) > 63: consists of the remaining key length\n+// note that partial key length is the length of the pk in nibbles\n+// Partial Key is the branch's key\n+// Value is:\n+// Children Bitmap | SCALE Branch Node Value | Hash(Enc(Child[i_1])) | Hash(Enc(Child[i_2])) | ... | Hash(Enc(Child[i_n]))\n+// Note that since the encoded branch stores the hash of the children nodes, we aren't able to reconstruct the child\n+// nodes from the encoding. This function instead stubs where the children are known to be with an empty leaf.\n+func (b *branch) Decode(r io.Reader, header byte) (err error) {\n+\tif header == 0 {","path":"trie/node.go","position":68,"original_position":68,"commit_id":"eeb82a9181bf7aba1efd3935918926f9aaec0bce","original_commit_id":"83d5222b81c1cd91ed1781b14c55ca9257bf14f4","user":{"login":"amerameen","id":2477984,"node_id":"MDQ6VXNlcjI0Nzc5ODQ=","avatar_url":"https://avatars2.githubusercontent.com/u/2477984?v=4","gravatar_id":"","url":"https://api.github.com/users/amerameen","html_url":"https://github.com/amerameen","followers_url":"https://api.github.com/users/amerameen/followers","following_url":"https://api.github.com/users/amerameen/following{/other_user}","gists_url":"https://api.github.com/users/amerameen/gists{/gist_id}","starred_url":"https://api.github.com/users/amerameen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amerameen/subscriptions","organizations_url":"https://api.github.com/users/amerameen/orgs","repos_url":"https://api.github.com/users/amerameen/repos","events_url":"https://api.github.com/users/amerameen/events{/privacy}","received_events_url":"https://api.github.com/users/amerameen/received_events","type":"User","site_admin":false},"body":"in which case would we have header == 0?","created_at":"2019-10-25T20:07:06Z","updated_at":"2019-10-25T20:31:51Z","html_url":"https://github.com/ChainSafe/gossamer/pull/352#discussion_r339219222","pull_request_url":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/ChainSafe/gossamer/pulls/comments/339219222"},"html":{"href":"https://github.com/ChainSafe/gossamer/pull/352#discussion_r339219222"},"pull_request":{"href":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352"}}},"pull_request":{"url":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352","id":331697962,"node_id":"MDExOlB1bGxSZXF1ZXN0MzMxNjk3OTYy","html_url":"https://github.com/ChainSafe/gossamer/pull/352","diff_url":"https://github.com/ChainSafe/gossamer/pull/352.diff","patch_url":"https://github.com/ChainSafe/gossamer/pull/352.patch","issue_url":"https://api.github.com/repos/ChainSafe/gossamer/issues/352","number":352,"state":"open","locked":false,"title":"trie: encode and decode trie for DB, save and load to/from DB","user":{"login":"noot","id":36753753,"node_id":"MDQ6VXNlcjM2NzUzNzUz","avatar_url":"https://avatars3.githubusercontent.com/u/36753753?v=4","gravatar_id":"","url":"https://api.github.com/users/noot","html_url":"https://github.com/noot","followers_url":"https://api.github.com/users/noot/followers","following_url":"https://api.github.com/users/noot/following{/other_user}","gists_url":"https://api.github.com/users/noot/gists{/gist_id}","starred_url":"https://api.github.com/users/noot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noot/subscriptions","organizations_url":"https://api.github.com/users/noot/orgs","repos_url":"https://api.github.com/users/noot/repos","events_url":"https://api.github.com/users/noot/events{/privacy}","received_events_url":"https://api.github.com/users/noot/received_events","type":"User","site_admin":false},"body":"## Changes\r\n- implement Decode functions for trie nodes (note that due to the recursive nature of branch encoding, it contains the hashes of its children, which can't be reconstructed. instead, the Decode function stubs where it knows its child should be with an empty node) either way, this function is only used in DecodeFromDB where the trie is recursively reconstructed\r\n- implement EncodeForDB and DecodeFromDB. Encode recursively encodes each node in the trie and SCALEs it and appends it to a byte array. Decode performs the opposite, it reads each node one at a time from the encoding and reconstructs the trie\r\n- implement StoreInDB and LoadFromDB. Store saves the trie in the DB at its root hash and Load loads a trie given a root hash. (later on, when we need to restore a certain state, we can do it from knowing the state hash)\r\n\r\n## Tests:\r\n```\r\ngo test ./trie/...\r\n```\r\n\r\n### Issues:\r\ncloses #324 ","created_at":"2019-10-23T19:03:57Z","updated_at":"2019-10-25T20:31:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"26206c08614184993f3be830066803c227cac4cc","assignee":null,"assignees":[],"requested_reviewers":[{"login":"dziabko","id":24738194,"node_id":"MDQ6VXNlcjI0NzM4MTk0","avatar_url":"https://avatars0.githubusercontent.com/u/24738194?v=4","gravatar_id":"","url":"https://api.github.com/users/dziabko","html_url":"https://github.com/dziabko","followers_url":"https://api.github.com/users/dziabko/followers","following_url":"https://api.github.com/users/dziabko/following{/other_user}","gists_url":"https://api.github.com/users/dziabko/gists{/gist_id}","starred_url":"https://api.github.com/users/dziabko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dziabko/subscriptions","organizations_url":"https://api.github.com/users/dziabko/orgs","repos_url":"https://api.github.com/users/dziabko/repos","events_url":"https://api.github.com/users/dziabko/events{/privacy}","received_events_url":"https://api.github.com/users/dziabko/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":1587405907,"node_id":"MDU6TGFiZWwxNTg3NDA1OTA3","url":"https://api.github.com/repos/ChainSafe/gossamer/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"0052cc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352/commits","review_comments_url":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352/comments","review_comment_url":"https://api.github.com/repos/ChainSafe/gossamer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ChainSafe/gossamer/issues/352/comments","statuses_url":"https://api.github.com/repos/ChainSafe/gossamer/statuses/eeb82a9181bf7aba1efd3935918926f9aaec0bce","head":{"label":"ChainSafe:noot/state-load","ref":"noot/state-load","sha":"eeb82a9181bf7aba1efd3935918926f9aaec0bce","user":{"login":"ChainSafe","id":27474093,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NDc0MDkz","avatar_url":"https://avatars1.githubusercontent.com/u/27474093?v=4","gravatar_id":"","url":"https://api.github.com/users/ChainSafe","html_url":"https://github.com/ChainSafe","followers_url":"https://api.github.com/users/ChainSafe/followers","following_url":"https://api.github.com/users/ChainSafe/following{/other_user}","gists_url":"https://api.github.com/users/ChainSafe/gists{/gist_id}","starred_url":"https://api.github.com/users/ChainSafe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChainSafe/subscriptions","organizations_url":"https://api.github.com/users/ChainSafe/orgs","repos_url":"https://api.github.com/users/ChainSafe/repos","events_url":"https://api.github.com/users/ChainSafe/events{/privacy}","received_events_url":"https://api.github.com/users/ChainSafe/received_events","type":"Organization","site_admin":false},"repo":{"id":168006517,"node_id":"MDEwOlJlcG9zaXRvcnkxNjgwMDY1MTc=","name":"gossamer","full_name":"ChainSafe/gossamer","private":false,"owner":{"login":"ChainSafe","id":27474093,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NDc0MDkz","avatar_url":"https://avatars1.githubusercontent.com/u/27474093?v=4","gravatar_id":"","url":"https://api.github.com/users/ChainSafe","html_url":"https://github.com/ChainSafe","followers_url":"https://api.github.com/users/ChainSafe/followers","following_url":"https://api.github.com/users/ChainSafe/following{/other_user}","gists_url":"https://api.github.com/users/ChainSafe/gists{/gist_id}","starred_url":"https://api.github.com/users/ChainSafe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChainSafe/subscriptions","organizations_url":"https://api.github.com/users/ChainSafe/orgs","repos_url":"https://api.github.com/users/ChainSafe/repos","events_url":"https://api.github.com/users/ChainSafe/events{/privacy}","received_events_url":"https://api.github.com/users/ChainSafe/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/ChainSafe/gossamer","description":"🕸️ Gossamer: The Golang Polkadot Runtime Environment Implementation (WIP)","fork":false,"url":"https://api.github.com/repos/ChainSafe/gossamer","forks_url":"https://api.github.com/repos/ChainSafe/gossamer/forks","keys_url":"https://api.github.com/repos/ChainSafe/gossamer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ChainSafe/gossamer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ChainSafe/gossamer/teams","hooks_url":"https://api.github.com/repos/ChainSafe/gossamer/hooks","issue_events_url":"https://api.github.com/repos/ChainSafe/gossamer/issues/events{/number}","events_url":"https://api.github.com/repos/ChainSafe/gossamer/events","assignees_url":"https://api.github.com/repos/ChainSafe/gossamer/assignees{/user}","branches_url":"https://api.github.com/repos/ChainSafe/gossamer/branches{/branch}","tags_url":"https://api.github.com/repos/ChainSafe/gossamer/tags","blobs_url":"https://api.github.com/repos/ChainSafe/gossamer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ChainSafe/gossamer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ChainSafe/gossamer/git/refs{/sha}","trees_url":"https://api.github.com/repos/ChainSafe/gossamer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ChainSafe/gossamer/statuses/{sha}","languages_url":"https://api.github.com/repos/ChainSafe/gossamer/languages","stargazers_url":"https://api.github.com/repos/ChainSafe/gossamer/stargazers","contributors_url":"https://api.github.com/repos/ChainSafe/gossamer/contributors","subscribers_url":"https://api.github.com/repos/ChainSafe/gossamer/subscribers","subscription_url":"https://api.github.com/repos/ChainSafe/gossamer/subscription","commits_url":"https://api.github.com/repos/ChainSafe/gossamer/commits{/sha}","git_commits_url":"https://api.github.com/repos/ChainSafe/gossamer/git/commits{/sha}","comments_url":"https://api.github.com/repos/ChainSafe/gossamer/comments{/number}","issue_comment_url":"https://api.github.com/repos/ChainSafe/gossamer/issues/comments{/number}","contents_url":"https://api.github.com/repos/ChainSafe/gossamer/contents/{+path}","compare_url":"https://api.github.com/repos/ChainSafe/gossamer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ChainSafe/gossamer/merges","archive_url":"https://api.github.com/repos/ChainSafe/gossamer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ChainSafe/gossamer/downloads","issues_url":"https://api.github.com/repos/ChainSafe/gossamer/issues{/number}","pulls_url":"https://api.github.com/repos/ChainSafe/gossamer/pulls{/number}","milestones_url":"https://api.github.com/repos/ChainSafe/gossamer/milestones{/number}","notifications_url":"https://api.github.com/repos/ChainSafe/gossamer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ChainSafe/gossamer/labels{/name}","releases_url":"https://api.github.com/repos/ChainSafe/gossamer/releases{/id}","deployments_url":"https://api.github.com/repos/ChainSafe/gossamer/deployments","created_at":"2019-01-28T17:40:01Z","updated_at":"2019-10-22T06:08:33Z","pushed_at":"2019-10-25T20:02:12Z","git_url":"git://github.com/ChainSafe/gossamer.git","ssh_url":"git@github.com:ChainSafe/gossamer.git","clone_url":"https://github.com/ChainSafe/gossamer.git","svn_url":"https://github.com/ChainSafe/gossamer","homepage":"","size":42405,"stargazers_count":83,"watchers_count":83,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":66,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":13,"open_issues":66,"watchers":83,"default_branch":"development"}},"base":{"label":"ChainSafe:development","ref":"development","sha":"db42a6bdbb302ba2033ee0249aff9337d47d366a","user":{"login":"ChainSafe","id":27474093,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NDc0MDkz","avatar_url":"https://avatars1.githubusercontent.com/u/27474093?v=4","gravatar_id":"","url":"https://api.github.com/users/ChainSafe","html_url":"https://github.com/ChainSafe","followers_url":"https://api.github.com/users/ChainSafe/followers","following_url":"https://api.github.com/users/ChainSafe/following{/other_user}","gists_url":"https://api.github.com/users/ChainSafe/gists{/gist_id}","starred_url":"https://api.github.com/users/ChainSafe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChainSafe/subscriptions","organizations_url":"https://api.github.com/users/ChainSafe/orgs","repos_url":"https://api.github.com/users/ChainSafe/repos","events_url":"https://api.github.com/users/ChainSafe/events{/privacy}","received_events_url":"https://api.github.com/users/ChainSafe/received_events","type":"Organization","site_admin":false},"repo":{"id":168006517,"node_id":"MDEwOlJlcG9zaXRvcnkxNjgwMDY1MTc=","name":"gossamer","full_name":"ChainSafe/gossamer","private":false,"owner":{"login":"ChainSafe","id":27474093,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NDc0MDkz","avatar_url":"https://avatars1.githubusercontent.com/u/27474093?v=4","gravatar_id":"","url":"https://api.github.com/users/ChainSafe","html_url":"https://github.com/ChainSafe","followers_url":"https://api.github.com/users/ChainSafe/followers","following_url":"https://api.github.com/users/ChainSafe/following{/other_user}","gists_url":"https://api.github.com/users/ChainSafe/gists{/gist_id}","starred_url":"https://api.github.com/users/ChainSafe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChainSafe/subscriptions","organizations_url":"https://api.github.com/users/ChainSafe/orgs","repos_url":"https://api.github.com/users/ChainSafe/repos","events_url":"https://api.github.com/users/ChainSafe/events{/privacy}","received_events_url":"https://api.github.com/users/ChainSafe/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/ChainSafe/gossamer","description":"🕸️ Gossamer: The Golang Polkadot Runtime Environment Implementation (WIP)","fork":false,"url":"https://api.github.com/repos/ChainSafe/gossamer","forks_url":"https://api.github.com/repos/ChainSafe/gossamer/forks","keys_url":"https://api.github.com/repos/ChainSafe/gossamer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ChainSafe/gossamer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ChainSafe/gossamer/teams","hooks_url":"https://api.github.com/repos/ChainSafe/gossamer/hooks","issue_events_url":"https://api.github.com/repos/ChainSafe/gossamer/issues/events{/number}","events_url":"https://api.github.com/repos/ChainSafe/gossamer/events","assignees_url":"https://api.github.com/repos/ChainSafe/gossamer/assignees{/user}","branches_url":"https://api.github.com/repos/ChainSafe/gossamer/branches{/branch}","tags_url":"https://api.github.com/repos/ChainSafe/gossamer/tags","blobs_url":"https://api.github.com/repos/ChainSafe/gossamer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ChainSafe/gossamer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ChainSafe/gossamer/git/refs{/sha}","trees_url":"https://api.github.com/repos/ChainSafe/gossamer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ChainSafe/gossamer/statuses/{sha}","languages_url":"https://api.github.com/repos/ChainSafe/gossamer/languages","stargazers_url":"https://api.github.com/repos/ChainSafe/gossamer/stargazers","contributors_url":"https://api.github.com/repos/ChainSafe/gossamer/contributors","subscribers_url":"https://api.github.com/repos/ChainSafe/gossamer/subscribers","subscription_url":"https://api.github.com/repos/ChainSafe/gossamer/subscription","commits_url":"https://api.github.com/repos/ChainSafe/gossamer/commits{/sha}","git_commits_url":"https://api.github.com/repos/ChainSafe/gossamer/git/commits{/sha}","comments_url":"https://api.github.com/repos/ChainSafe/gossamer/comments{/number}","issue_comment_url":"https://api.github.com/repos/ChainSafe/gossamer/issues/comments{/number}","contents_url":"https://api.github.com/repos/ChainSafe/gossamer/contents/{+path}","compare_url":"https://api.github.com/repos/ChainSafe/gossamer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ChainSafe/gossamer/merges","archive_url":"https://api.github.com/repos/ChainSafe/gossamer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ChainSafe/gossamer/downloads","issues_url":"https://api.github.com/repos/ChainSafe/gossamer/issues{/number}","pulls_url":"https://api.github.com/repos/ChainSafe/gossamer/pulls{/number}","milestones_url":"https://api.github.com/repos/ChainSafe/gossamer/milestones{/number}","notifications_url":"https://api.github.com/repos/ChainSafe/gossamer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ChainSafe/gossamer/labels{/name}","releases_url":"https://api.github.com/repos/ChainSafe/gossamer/releases{/id}","deployments_url":"https://api.github.com/repos/ChainSafe/gossamer/deployments","created_at":"2019-01-28T17:40:01Z","updated_at":"2019-10-22T06:08:33Z","pushed_at":"2019-10-25T20:02:12Z","git_url":"git://github.com/ChainSafe/gossamer.git","ssh_url":"git@github.com:ChainSafe/gossamer.git","clone_url":"https://github.com/ChainSafe/gossamer.git","svn_url":"https://github.com/ChainSafe/gossamer","homepage":"","size":42405,"stargazers_count":83,"watchers_count":83,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":66,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":13,"open_issues":66,"watchers":83,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352"},"html":{"href":"https://github.com/ChainSafe/gossamer/pull/352"},"issue":{"href":"https://api.github.com/repos/ChainSafe/gossamer/issues/352"},"comments":{"href":"https://api.github.com/repos/ChainSafe/gossamer/issues/352/comments"},"review_comments":{"href":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352/comments"},"review_comment":{"href":"https://api.github.com/repos/ChainSafe/gossamer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ChainSafe/gossamer/pulls/352/commits"},"statuses":{"href":"https://api.github.com/repos/ChainSafe/gossamer/statuses/eeb82a9181bf7aba1efd3935918926f9aaec0bce"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"amerameen"}}