near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.3k stars 605 forks source link

Consider limiting trie key length by 32 bytes #9363

Open Longarithm opened 1 year ago

Longarithm commented 1 year ago

Eth model assumes that key length is always 32 bytes (Zulip). We don't, but it complicates things for us.

Most contract devs use short keys, as they benefit from low costs, but it's possible to create a key of 2 KB size, which trie depth can be unpleasantly big. We should consider replacing these keys in trie with their hashes, so that trie depth will be always limited by 64 (nibbles).

If we proceed with other tree structure like AVL (discussion), then it won't be needed because tree depth will depend only on number of keys.

jakmeier commented 1 year ago

For flat storage, could we keep using the non-hashed keys? Or are long keys also problematic there?

Keeping plain keys would presumably be better for data locality. But admittedly, I don't think we have much data to back up this claim.

Longarithm commented 1 year ago

Yes, for flat storage we should keep long keys.