Rewind: Efficient rewinding
Summary
We should implement a more efficient way to rewind accounts. Currently to do it we need to query the latest account state and then fetch preceding transactions to undo the changes. This is slow and it doesn't support rewinding some information such as participation keys.
Here are two possible ways to approach this problem.
- Snapshot account state every x rounds. Rewinding would pick the nearest snapshot below the given round and apply the transactions between the snapshot round and the given round.
- Maintain an array (db table) with the following format: [(round, new balance)] with elements sorted by the round. For every round a balance (or other info) changes, we add an entry to the array. Querying a balance before some round then requires one binary search.
Scope/Requirements
Need to change db schema.
Urgency/Relative Priority
Not urgent but nice to have.
@algorotem @winder
A few accounts do most of the changing. Most accounts change rarely and have few txns on them at all. 9.2 million accounts have 171 txns or fewer, 89043 accounts have more than that.
How much is rewind actually being used in deployed systems?
It's a good question. Another possibility is to remove this functionality.
Rewinding is currently the only way I am aware of to have a snapshot of the balances of a set of accounts at a given time. If you did not have rewinding, you could not do it.
Concrete example: you own accounts A and B.
You want to know your total amount of Algos.
The only way I currently know how to do it is first query the balance for A and then query the balance for B with the same round as the response for A.
If you do not do that and naively query the balance for both accounts, you may end up arbitrary increase your total amount of Algos if a transaction from A to B happened between the two calls.
Another use case where you need rewinding: you need a snapshot of the amounts of all Algos at a given round as it defines their weight in a voting process or something like that.
Finally, I have seen people on forum wanting to access past application states.
Hi, I would like to upvote efficient rewind..
Use case: in Vote Coin we calculate each account voting power according to the block in which is defined end of the voting session. There is currently no efficient way of getting simple algo/asset balance at specific round at specific account (or list of accounts)
We do it at the moment by using https://algoindexer.algoexplorerapi.io/v2/assets/452399768/balances?round=18988231 which is not very efficient especially if there is many owners of the assets.
https://forum.algorand.org/t/rewinding-past-txn-type-appl-is-not-currently-supported/5930
see vote coin specifications https://www.vote-coin.com/specifications/introduction
i am trying to extend the Vote Coin solution to be usable also for Algo
is there ANY way how can i get the Algo balance of the account BITSCVQHPCD7XAIYYEA5B3F3PWC57IRSIUIWPZV6JXFWUVMO7WQCXSP7NE at round 16024568 ?