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

New AddressIndexer leveraging CoinView #1031

Open
wants to merge 21 commits into
base: release/1.6.0.0
Choose a base branch
from

Conversation

quantumagi
Copy link
Contributor

@quantumagi quantumagi commented Aug 9, 2022

This is a reduced version of the earlier PR #995 with not-directly-relevant concerns split-off into separate PRs.

The PR replaces the current (LiteDB) AddressIndexer implementation and shares the CoinDb repository (LevelDb and optionally RocksDb or DBreeze).

Adding balance recording (for ALL addresses) to CoinView ensures a consistent view across available UTXO's and address balances. This is also a faster implementation than is provided by the current AddressIndexer. Only a fraction of a second (~40 ms) response time was observed to return the current balance AND ~1800 balance adjustments all the way to genesis. This does not require compaction and neither is it supported.

The cumulative balance is recorded in the Balance table and adjustments in the BalanceAdjustment table. This allows GetBalance to quickly supply the latest balance and if required a history of balances.

The code deals with the following issues:

  • Indexing balances and balance changes.
  • Keeping track of the height up to which balances are indexed so that address indexing can be toggled on/off without resulting in gaps and without requiring a complete re-build of the coin view/database. This logic also voids the need for any separate migration code.
  • Replacing AddressIndexer with a new implementation.

Note: Similar to SQLiteWalletRepository and for best performance, the code tracks destinations (vs addresses). This requires any addresses queried to be convertible to destinations. This is assumed to be so for the current use-cases.

/// <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);

@quantumagi quantumagi requested a review from zeptin August 24, 2022 13:35
zeptin
zeptin previously approved these changes Sep 3, 2022
@fassadlr fassadlr changed the base branch from release/1.4.0.0 to release/1.5.0.0 October 21, 2022 12:47
@fassadlr fassadlr added 1.6.0.0 and removed 1.4.0.0 labels Oct 21, 2022
@quantumagi quantumagi requested a review from zeptin October 31, 2022 10:56
@quantumagi quantumagi changed the title Add GetBalance to CoinView New AddressIndexer leveraging GetBalance on CoinView Oct 31, 2022
@quantumagi quantumagi changed the title New AddressIndexer leveraging GetBalance on CoinView New AddressIndexer leveraging the GetBalance of CoinView Oct 31, 2022
@quantumagi quantumagi changed the title New AddressIndexer leveraging the GetBalance of CoinView New AddressIndexer leveraging CoinView Nov 1, 2022
zeptin
zeptin previously approved these changes Nov 2, 2022
@quantumagi quantumagi requested a review from fassadlr November 2, 2022 07:41
@quantumagi
Copy link
Contributor Author

quantumagi commented Nov 2, 2022

@fassadlr , can you please have a look at this as well and perhaps comment on whether this is good to merge into 1.5.

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