Description
The main issue with the cost of e.g. getBalance()
is the fact that the account lookup in the database might be needed. This idea is to split the account loading from the accessing account metadata.
Instead of
getBalance(address, resultOffset);
we should have
handle = loadAccount(address);
getBalance(handle, resultOffset);
Similarly to getBalance()
there should be getters for code hash, code, code size and others.
Pros
- The cost of account lookup is separated from the cost of the getter.
- Getting information about the current account should be cheap because it is already loaded (the handle to the current account could be predefined).
- The cost of accessing the same account multiple times is lower.
Cons
- Handles must be deterministic as they may leak. Simple solution would be to have an array of loaded accounts and return the index in this array. Each call to
loadAccount
would append new entry to the array. - Contracts are responsible of accounts management.
Alternatives
-
Just dump account matadata to memory:
loadAccount(memoryOffset)
. This is simpler, but might waste some memory when contract is not interested in all data. Is is also not extensible, i.e. we cannot change the account representation in the future. -
Extension of the alternative 1 where the contract specify the bit mask of account fields it is interested in, e.g.
loadAccount(BALANCE | NONCE, memoryOffset)
. This at least allows adding more fields to the account in the future. But the output would be a mess, especially when getting the account code is considered.