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 ?

1 Answer 1

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.


7
  • 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
    Commented Mar 8, 2018 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
    Commented Mar 8, 2018 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
    Commented Mar 8, 2018 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
    Commented Mar 8, 2018 at 16:04
  • 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
    Commented Mar 8, 2018 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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