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

CoinsRegistry: Introduce CoinsByPubKeys #11571

Merged

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Sep 25, 2023

Alternative to #11534

The idea of this PR is to remove HdPubKey.Coins and move it to CoinsRegistry which feels like a better place to put it conceptually.

@kiminuo kiminuo marked this pull request as draft September 25, 2023 07:12
Comment on lines -140 to -144
public bool RegisterToHdPubKey()
=> HdPubKey.Coins.Add(this);

public bool UnregisterFromHdPubKey()
=> HdPubKey.Coins.Remove(this);
Copy link
Collaborator Author

@kiminuo kiminuo Sep 25, 2023

Choose a reason for hiding this comment

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

Functionality was moved to CoinsRegistry.

@@ -246,10 +281,10 @@ public async Task ConfirmedDoubleSpendAsync()
int doubleSpendReceived = 0;
transactionProcessor.WalletRelevantTransactionProcessed += (s, e) =>
{
var doubleSpents = e.SuccessfullyDoubleSpentCoins;
if (doubleSpents.Any())
var doubleSpends = e.SuccessfullyDoubleSpentCoins;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

typo

public class TransactionProcessorTests
{
[Fact]
public async Task TransactionDoesNotCointainCoinsForTheWalletAsync()
public async Task TransactionDoesNotContainCoinsForTheWalletAsync()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

typo

@@ -68,8 +67,6 @@ public double AnonymitySet
private set => RaiseAndSetIfChanged(ref _anonymitySet, value);
}

public HashSet<SmartCoin> Coins { get; } = new HashSet<SmartCoin>();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced with private Dictionary<HdPubKey, HashSet<SmartCoin>> CoinsByPubKeys { get; } = new(); in CoinsRegistry.

Comment on lines +99 to +105
if (!CoinsByPubKeys.TryGetValue(coin.HdPubKey, out HashSet<SmartCoin>? coinsOfPubKey))
{
coinsOfPubKey = new();
CoinsByPubKeys.Add(coin.HdPubKey, coinsOfPubKey);
}

coinsOfPubKey.Add(coin);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is slightly longer but we can have a helper to make it shorter. But that would be a good change for another PR I guess.

Copy link
Collaborator

@turbolay turbolay Sep 25, 2023

Choose a reason for hiding this comment

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

Not sure it is required. Especially with #11516 where the CoinsRegistry would basically be a succession of Dictionary.TryGetValue calls

EDIT: I'm answering to your comment, not talking about the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok :)

{
coinsOfPubKey.Remove(coin);

if (coinsOfPubKey.Count == 0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If a single HdPubKey is used a lot, then we should allocate less than now.

Copy link
Collaborator

@turbolay turbolay left a comment

Choose a reason for hiding this comment

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

cACK, implementation LGTM
This is also the only solution I could think about to remove HdPubKey.Coins

Comment on lines +99 to +105
if (!CoinsByPubKeys.TryGetValue(coin.HdPubKey, out HashSet<SmartCoin>? coinsOfPubKey))
{
coinsOfPubKey = new();
CoinsByPubKeys.Add(coin.HdPubKey, coinsOfPubKey);
}

coinsOfPubKey.Add(coin);
Copy link
Collaborator

@turbolay turbolay Sep 25, 2023

Choose a reason for hiding this comment

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

Not sure it is required. Especially with #11516 where the CoinsRegistry would basically be a succession of Dictionary.TryGetValue calls

EDIT: I'm answering to your comment, not talking about the code.

@kiminuo kiminuo marked this pull request as ready for review September 25, 2023 12:43
Copy link
Collaborator

@lontivero lontivero left a comment

Choose a reason for hiding this comment

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

LGTM

@kiminuo kiminuo merged commit d13f93e into WalletWasabi:master Sep 25, 2023
6 of 7 checks passed
@kiminuo kiminuo deleted the feature/2023-09-25-HdPubKey-remove-coins branch September 25, 2023 13:04
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.

None yet

3 participants