indexer icon indicating copy to clipboard operation
indexer copied to clipboard

Rewind: Efficient rewinding

Open tolikzinovyev opened this issue 4 years ago • 7 comments

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.

  1. 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.
  2. 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.

tolikzinovyev avatar Mar 09 '21 21:03 tolikzinovyev

@algorotem @winder

tolikzinovyev avatar Mar 09 '21 21:03 tolikzinovyev

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?

brianolson avatar Mar 09 '21 22:03 brianolson

It's a good question. Another possibility is to remove this functionality.

tolikzinovyev avatar Mar 10 '21 16:03 tolikzinovyev

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.

fabrice102 avatar Mar 23 '21 04:03 fabrice102

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

scholtz avatar Feb 01 '22 20:02 scholtz

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 ?

scholtz avatar Feb 19 '22 19:02 scholtz