parallelchain-io / parallelchain-protocol

Specification for the ParallelChain (and ParallelChain Mainnet) blockchain protocols.
https://parallelchain.io
1 stars 1 forks source link

World state and storage keys contain extra & unnecessary "visibility" byte #4

Closed lyulka closed 10 months ago

lyulka commented 1 year ago

Protocol version: 0.4.0+

Bug discovered in reference implementation pchain-world-state after launch: image

This "visibility" byte had a purpose in very early versions of the protocol, when the world state and storage weren't delineated as separate MPTs, but were part of a single MPT, and delineated using the visibility byte (i.e., world state keys would be "protected", and storage keys would be "public").

This byte was removed in the protocol, but was unknowingly retained in the reference implementation.

The protocol will have to be modified to make this canon.

This is difficult to fix without having to very invasively restructure the trie, so this will won't be fixed for the foreseeable future.

lyulka commented 11 months ago

I discussed with @TLiu2084 and the tentative consensus is that it is feasible to re-build the world state trie and all storage tries in the upgrade to protocol version 0.5 to fix this issue as well as #6 and any other issues we may find in the world state in the coming weeks.

We have run code that iterated through all keys in the world state trie on hardware comparable to a Mainnet node and it took about ~1.5 seconds. Also reading all of the keys in every storage trie as well as writing these keys into new tries will probably take longer, but we envision that it will take at most the same order of magnitude as a block time (~10 seconds).

A more thorough experiment is needed, but if we find that a world state re-build will take more than a block time, then we are willing to set a higher block time near the v0.5 upgrade block by overriding Pacemaker.

lyulka commented 10 months ago

Merged into and will be fixed in #8.