feat: create genesis block#183
Merged
Merged
Conversation
fmoletta
reviewed
Jul 29, 2024
| let _genesis = read_genesis_file(genesis_file_path); | ||
| let mut store = Store::new("storage.db", EngineType::InMemory).expect("Failed to create Store"); | ||
| let genesis = read_genesis_file(genesis_file_path); | ||
| let _ = store.add_initial_state(genesis); |
Contributor
There was a problem hiding this comment.
Could we use an expect here instead of ignoring the error?
mpaulucci
reviewed
Jul 29, 2024
| let root = | ||
| PatriciaMerkleTree::<_, _, Keccak256>::compute_hash_from_sorted_iter(rlp_storage.iter()); | ||
| pub fn compute_storage_root(storage: &BTreeMap<H256, H256>) -> H256 { | ||
| let mut pmt = PatriciaMerkleTree::<Vec<u8>, Vec<u8>, Keccak256>::new(); |
Collaborator
There was a problem hiding this comment.
nit: the short way to describe a patricia merkle tree is trie, or in this case maybe storage_trie
mpaulucci
reviewed
Jul 29, 2024
| let mut v_buf = vec![]; | ||
| let k_buf = Keccak256::new_with_prefix(k).finalize().to_vec(); | ||
| v.encode(&mut v_buf); | ||
| pmt.insert(k_buf, v_buf); |
Collaborator
There was a problem hiding this comment.
you were saying that if you inserted key value pairs in different order then the root would have been different?
Contributor
Author
There was a problem hiding this comment.
Not really. See #203.
There is an utility function to calculate root hash without actually building the trie, provided the list is sorted
Contributor
Author
There was a problem hiding this comment.
It was being used here and calculating an incorrect storage_root because the key hashes were not sorted.
mpaulucci
approved these changes
Jul 30, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Create initial block and accounts from genesis and persist them in Store
Description
Closes #48