Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate the trie node encoding and decode code #262

Merged
merged 8 commits into from
Mar 3, 2023

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Mar 3, 2023

Close #45

There are currently two modules that are extremely similar: node_value and proof_node_codec.
This is because a node in a proof is the same encoding as a node in the trie. A proof is simply a subset of the trie.

This PR merges them into a new trie_node.rs module.

trie_node.rs is identical to proof_node_codec.rs except that:

  • Decoded now accepts a second template parameter for the type of the slice of the children.
  • It has the calculate_merkle_value function of node_value, and node_value::Output is now trie_node::MerkleValueOutput.

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼─────────────────────────────────────────────────────────────────────────────────────
       -2114 ┊ smoldot::trie::node_value::calculate_merkle_value::h1a08e5db1df4bf3c
       -1819 ┊ smoldot::trie::node_value::calculate_merkle_value::hae8592be1c077277
       -1686 ┊ smoldot::trie::node_value::calculate_merkle_value::h7e4624f4826cdd80
       -1639 ┊ smoldot::trie::node_value::calculate_merkle_value::h0120a2bdbda20b0b
       -1639 ┊ smoldot::trie::node_value::calculate_merkle_value::h978c157ab8a4f6c7
       -1560 ┊ smoldot::trie::proof_node_codec::decode::haf5019ff28b96e53
       +1560 ┊ smoldot::trie::trie_node::decode::hdfea7f1c265892fb
       -1058 ┊ smoldot::trie::node_value::calculate_merkle_value::hdd8b7fe7b28a4ccd
        +934 ┊ smoldot::trie::trie_node::calculate_merkle_value::h6e768a76e876b758
        +903 ┊ smoldot::trie::trie_node::calculate_merkle_value::h5d03bd74f43e0db3
        +812 ┊ smoldot::trie::trie_node::encode::he0ccb24812429c95
        +447 ┊ smoldot::trie::trie_node::encode::h9dff752a3890bcc5
        +425 ┊ smoldot::trie::calculate_root::StorageValue::inject::h7947098e496f0d60
        +330 ┊ <&T as core::fmt::Display>::fmt::h5a4a3c6d1b68e313
        -330 ┊ <&T as core::fmt::Display>::fmt::h8dccc91510640d2b
        -327 ┊ <smoldot::trie::proof_node_codec::Error as core::fmt::Debug>::fmt::h3baa60ab5ba68d14
        +327 ┊ <smoldot::trie::trie_node::Error as core::fmt::Debug>::fmt::h90ff66766c13b5f9
        +294 ┊ smoldot::trie::calculate_root::StorageValue::inject::h2d8bc09a9ea7bc1e
        +294 ┊ smoldot::trie::calculate_root::StorageValue::inject::ha643bf8bfc88bd86
        +293 ┊ smoldot::trie::calculate_root::StorageValue::inject::h33c7b8c3ecb5e119
       +2478 ┊ ... and 100 more.
        +635 ┊ Σ [120 Total Rows]

@tomaka tomaka added this pull request to the merge queue Mar 3, 2023
Merged via the queue into smol-dot:main with commit 51d3a74 Mar 3, 2023
@tomaka tomaka deleted the dedup-node-encode branch March 10, 2023 17:12
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.

The trienodevalue and trieproofnodecodec modules are kind of redundant
1 participant