near / near-sdk-rs

Rust library for writing NEAR smart contracts
https://near-sdk.io
Apache License 2.0
466 stars 249 forks source link

Stabilize `near_sdk::store` collections #818

Open austinabell opened 2 years ago

austinabell commented 2 years ago

Work started in #815 to stabilize, but for each of them:

austinabell commented 2 years ago

Very skeptical to stabilize TreeMap. Would be nice to have an optimization that doesn't involve brute force searching when iterating. The collection is pretty unusable as-is

itegulov commented 2 years ago

Very skeptical to stabilize TreeMap. Would be nice to have an optimization that doesn't involve brute force searching when iterating. The collection is pretty unusable as-is

Shared my perspective on this in https://github.com/near/near-sdk-rs/issues/928, lmk what you think there

bugproof commented 1 year ago

I don't really get why the new near_sdk::store::Vector doesn't use u64 anymore but u32, if you plan on having more than u32::MAX items you cannot do this with this change. I guess your only option will remain only UnorderedMap/LookupMap. I'd like to know the reason behind this breaking change.

austinabell commented 1 year ago

I don't really get why the new near_sdk::store::Vector doesn't use u64 anymore but u32, if you plan on having more than u32::MAX items you cannot do this with this change. I guess your only option will remain only UnorderedMap/LookupMap. I'd like to know the reason behind this breaking change.

The primary reason is that a few of the std APIs used in conjunction with this (namely iterators) use usize, and having the indices be u64 in a 32-bit wasm architecture, can lead to silent bugs and foot guns.

Do you plan to have more than 4 billion entries in your Vector? It intuitively doesn't seem economically or technically feasible to store that many entries on chain, even with small value serializations. I'd say if you have an extreme example like this and you need that, I'd just fork that specific collection and change the indices; it would be a simple enough change to make.

bugproof commented 1 year ago

https://users.rust-lang.org/t/are-there-any-negative-implications-of-using-u64-in-wasm32/57419/2

Do you plan to have more than 4 billion entries in your Vector?

No, it's an extreme example but it's possible to reach that theoretically. There are 8 billion people in the world. Dapps should be able to scale to handle huge loads to be able to compete with web2 based platforms. Even fungible token contracts practically could reach over 4 billion entries if you have 4 billion near accounts and each has X amount of USDT