0

How does a smart contract fetch stored data (for example, EmployeeName) from the node? Does it search through the entire chain? But searching through the entire chain would take just too long. There must be a quicker way.

1

Ethereum uses Patricia Merkle trees (known as a 'Trie') to store data. One global 'State Trie' has an entry for each account. Each account entry contains its own 'Storage Trie', and this is where the data for a contract is found.

These tries perform lookups, as well as edits and deletes in O(log(n)) efficiency, meaning that if there are n entries the time taken to lookup a particular entry will be proportional to log(n).

The ethereum wiki has a page on Patricia-Merkle trees (https://github.com/ethereum/wiki/wiki/Patricia-Tree)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.