-
Notifications
You must be signed in to change notification settings - Fork 492
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
CoinsRegistry
: Introduce CoinsByPubKeys
#11571
Conversation
public bool RegisterToHdPubKey() | ||
=> HdPubKey.Coins.Add(this); | ||
|
||
public bool UnregisterFromHdPubKey() | ||
=> HdPubKey.Coins.Remove(this); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
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
.
if (!CoinsByPubKeys.TryGetValue(coin.HdPubKey, out HashSet<SmartCoin>? coinsOfPubKey)) | ||
{ | ||
coinsOfPubKey = new(); | ||
CoinsByPubKeys.Add(coin.HdPubKey, coinsOfPubKey); | ||
} | ||
|
||
coinsOfPubKey.Add(coin); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
if (!CoinsByPubKeys.TryGetValue(coin.HdPubKey, out HashSet<SmartCoin>? coinsOfPubKey)) | ||
{ | ||
coinsOfPubKey = new(); | ||
CoinsByPubKeys.Add(coin.HdPubKey, coinsOfPubKey); | ||
} | ||
|
||
coinsOfPubKey.Add(coin); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Alternative to #11534
The idea of this PR is to remove
HdPubKey.Coins
and move it toCoinsRegistry
which feels like a better place to put it conceptually.