6

In Iota, addresses are defined by an incremental index from 0 to 2,147,483,647 (potentially infinite depending on the IRI implementation).

For the sake of the example, let's say the last address you used was at index 1,000,000

In order to get the balance of a seed, you'd need to query all transactions referencing addresses from index 0 to index 1,000,000.
Even with efficient algorithms such as MapReduce, that seems like a heavy operation on a database + computation for such a simple request.


  • Is the premise correct ?
  • If correct, is there a mechanism to limit the weight of the operation ?
  • Overall, how will large address indexes affect scalability in the long run ?
blockmined
  • 710
  • 1
  • 4
  • 9
aguadoe
  • 241
  • 1
  • 7

1 Answers1

2

You would likely store

  1. your seed
  2. the index of the first unspent address

The way IOTA address generation works makes some things very easy:
Let's say, your seed is AAAAAA...

AAAAAA... + 0 = AAAAAA... → to generate your first address
AAAAAA... + 1 = BAAAAA... → to generate your second address
AAAAAA... + 2 = CAAAAA... → to generate your third address
...
AAAAAA... + index → to generate your "current" address.

So even the index is 1,000,000, it does not affect the scalability you can simply add it to your seed.

You can also use your original seed + index to get your new seed every so often. If you do that, you can use stateless wallets.


The last address I used was at index 1,000,000. How to get my balance.

You just take your seed, add 1,000,000 and generate the address. Then you ask a full node (and its database) what the addresses' balance is.
Then you add 1,000,001 to your seed and generate the address. Then you ask a full node again.

You repeat this process until you find an address that has no transactions, add all of the individual balances up and you have your final balance.

You don't have to call getBalance(addressN) a million times. Just once for every address that really has a balance.


Zauz
  • 4,454
  • 15
  • 42
  • 2
    The questions are not about address generation, but about the cost of querying all addresses into a database (on a full node). If my "current" address is at index 1,000,000 I'll have to call getBalance(addressN) 1,000,000 times, thus hitting the node's database 1,000,000 times. – aguadoe Mar 08 '18 at 13:51
  • To get the total balance you could use the iota.lib.js library and run getInputs with seed as argument. It will get all possible inputs from all 1,000,000 addresses of your seed and return them with the total balance. I think that this kind of operation can affect the load of the used fullnode but it doesn't affect the scalability of Tangle itself. – blockmined Mar 08 '18 at 15:21
  • @Zauz, in response to the edit, if the wallet is stateless or if you switched wallet, how would you know which address actually has a balance ? Also, you could have funds left in previous addresses, forcing you to check every address. – aguadoe Mar 08 '18 at 16:02
  • @RobertoGiorgetti It might slow the network since more ressources for a balance query means less ressources for other actions (e.g verifying transactions) – aguadoe Mar 08 '18 at 16:04
  • @aguadoe You are right – blockmined Mar 08 '18 at 16:17
  • 2
    If you use a stateless wallet, you could switch to a new seed every so often or "trim" your seed and switch to the new one. Otherwise this could be a problem (but it isn't because everybody will use stateful wallets and/or not use a million addresses). Nodes would probably reject connections or block clients that want to know the balances of a million addresses. – Zauz Mar 08 '18 at 16:25
  • @Zauz, Using a new seed is indeed a decent solution to the problem. This problem is obviously very theorical and probably won't happen in practice, but IoT devices ought to produce more transactions/sec than humans, hence my question. If you post your comment as a response, I'll accept it – aguadoe Mar 09 '18 at 07:51