uport-project / ethr-did-registry

Ethereum registry for ERC-1056 ethr did methods
Apache License 2.0
178 stars 71 forks source link

[Question] Contract storage architecture #50

Closed aaliakseyenka closed 2 years ago

aaliakseyenka commented 2 years ago

Is your feature request related to a problem? Please describe. This is more a question about architecture decision on how data is stored in contract.

Describe the solution you'd like If I understand it right, the contract uses events as storage for different manipulations with did. As a result we have to search through entire network to get block data and analyse for changes(https://github.com/decentralized-identity/ethr-did-resolver/blob/master/src/resolver.ts#L75). I might ask a nubby question, although wouldn't it be more sufficient to store actual data in the latest block? Ie. create proper mappings and save/extract when needed. In terms of speed that should be much better.

Appreciate any comments on that.

mirceanis commented 2 years ago

Thanks for asking. Yes, the contract uses events for storage. This is by design to reduce the cost of gas.

Storing the data in normal contract storage would be possible, but much much more expensive. Each event has a pointer to the latest change for that DID, so you don't have to search through the entire network, you only need to search the logs of a few specific blocks. If you want to speed up the process, it should be relatively easy to cache the list of events (see also https://github.com/decentralized-identity/ethr-did-resolver/issues/150)

Please close this if you think my answer is enough.

aaliakseyenka commented 2 years ago

@mirceanis thanks a lot for explanation. that all makes sense