Skip to content

feat: create genesis block#183

Merged
mpaulucci merged 13 commits into
mainfrom
create_genesis_block
Jul 30, 2024
Merged

feat: create genesis block#183
mpaulucci merged 13 commits into
mainfrom
create_genesis_block

Conversation

@ElFantasma

Copy link
Copy Markdown
Contributor

Motivation

Create initial block and accounts from genesis and persist them in Store

Description

Closes #48

@ElFantasma ElFantasma changed the title feat: Create genesis block - WIP feat: create genesis block - WIP Jul 18, 2024
@ElFantasma ElFantasma marked this pull request as ready for review July 29, 2024 13:44
@ElFantasma ElFantasma requested a review from a team as a code owner July 29, 2024 13:44
Comment thread cmd/ethereum_rust/ethereum_rust.rs Outdated
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we use an expect here instead of ignoring the error?

Comment thread crates/core/types/account.rs Outdated
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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: the short way to describe a patricia merkle tree is trie, or in this case maybe storage_trie

Comment thread crates/core/types/account.rs Outdated
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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you were saying that if you inserted key value pairs in different order then the root would have been different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really. See #203.

There is an utility function to calculate root hash without actually building the trie, provided the list is sorted

@ElFantasma ElFantasma Jul 29, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was being used here and calculating an incorrect storage_root because the key hashes were not sorted.

@ElFantasma ElFantasma changed the title feat: create genesis block - WIP feat: create genesis block Jul 29, 2024
@mpaulucci mpaulucci merged commit 265c7ea into main Jul 30, 2024
@mpaulucci mpaulucci deleted the create_genesis_block branch July 30, 2024 08:57
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.

Create genesis block from configuration

3 participants