Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetBalance to CoinView #995

Closed

Conversation

quantumagi
Copy link
Contributor

@quantumagi quantumagi commented Jun 11, 2022

Merge PR #110 first.

Implements a very fast IEnumerable<(uint height, long satoshis)> GetBalance(TxDestination txDestination);

The first enumeration value comes from the Balance table and subsequent values are adjusted via the BalanceAdjustment table.

Only a fraction of a second (~40 ms) response time was observed to return ~1800 balance adjustments all the way to genesis.

Implemented ONCE in Coindb<T> which replaces LevelDbCoindb and RocksDbCoindb.

The code deals with the following issues:

  • Keeping track of the height up to which balances are indexed so that address indexing can be toggled on/off without resulting in gaps.
  • Replacing AddressIndexer with AddressIndexerCV and respecting the -addressindex setting.
  • Adding missing XML comments.
  • Adding the IDb compliant wrapper classes RocksDb and LevelDb.
/// <summary>
/// Returns a combination of (height, satoshis) values with the cumulative balance up to the corresponding height.
/// </summary>
/// <param name="txDestination">The destination value derived from the address being queried.</param>
/// <returns>A combination of (height, satoshis) values with the cumulative balance up to the corresponding height.</returns>
/// <remarks>Balance updates (even when nett 0) are delivered for every height at which transactions for the address had been recorded 
/// and as such the returned heights can be used in conjunction with the block store to discover all related transactions.</remarks>
IEnumerable<(uint height, long satoshis)> GetBalance(TxDestination txDestination);

Instead of adding migration code the coin database is automatically truncated and re-built (+- 5 minutes).

@quantumagi quantumagi requested review from zeptin and fassadlr June 11, 2022 12:55
@quantumagi
Copy link
Contributor Author

Still testing.


if (row == null)
throw new InvalidOperationException($"No rewind data found for block at height {height}.");

batch.Delete(BitConverter.GetBytes(height));
Copy link
Contributor Author

@quantumagi quantumagi Jun 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix - the table prefix is missing here and the bytes should be in big endian order.

@fassadlr
Copy link
Contributor

fassadlr commented Jun 12, 2022

Hi Gustav, release 1.3 will go out tomorrow as we are already in RC with the masternodes. Can you please point this to

https://github.com/stratisproject/StratisFullNode/tree/release/1.3.1.0

@quantumagi quantumagi changed the base branch from release/1.3.0.0 to release/1.3.1.0 June 12, 2022 09:23
@quantumagi quantumagi requested a review from zeptin June 13, 2022 10:17
@quantumagi quantumagi changed the base branch from release/1.3.1.0 to release/1.4.0.0 July 2, 2022 12:34
@quantumagi quantumagi marked this pull request as ready for review July 4, 2022 14:10
@quantumagi quantumagi marked this pull request as draft July 11, 2022 07:50
@quantumagi
Copy link
Contributor Author

See #1031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants