planetarium / libplanet

Blockchain in C#/.NET for on-chain, decentralized gaming
https://docs.libplanet.io/
GNU Lesser General Public License v2.1
506 stars 142 forks source link

BlockChain<T>.GetStates() returns significantly slow if the height is too high #189

Closed dahlia closed 5 years ago

dahlia commented 5 years ago

BlockChain<T>.GetStates(A) where A is nonexistent (i.e., never used) returns significantly slow if the height is enough high. Currently IStore.GetBlockStates() returns only a set of updated states, not a complete set of existent accounts. This means that BlockChain<T>.GetStates(A) needs to descend to the bottom (i.e., the genesis block) in order to determine if A is nonexistent.

dahlia commented 5 years ago

It seems to happen even if a request address is existent. The current implementation compares two sets (more exactly, intended to be a set but represented as IEnumerable<Address>) by arbitrarily ordered sequences:

https://github.com/planetarium/libplanet/blob/65bc8cdbc729991bc4aeb940c983fe99405ddc9c/Libplanet/Blockchain/BlockChain.cs#L178