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

WalletFilterProcessor: Minor cleanup #12126

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Dec 22, 2023

No description provided.

Comment on lines -211 to -220
/// <summary>
/// Used by test to emulate database.
/// </summary>
internal void AddToCache(IEnumerable<FilterModel> filters)
{
foreach (var filter in filters)
{
FiltersCache[filter.Header.Height] = filter;
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Inlined to tests.

Comment on lines -199 to -209
private async Task<FilterModel> UpdateFiltersCacheAndReturnFirstAsync(uint startingHeight, CancellationToken cancellationToken)
{
FiltersCache.Clear();
var filtersBatch = await BitcoinStore.IndexStore.FetchBatchAsync(new Height(startingHeight), MaxNumberFiltersInMemory, cancellationToken).ConfigureAwait(false);
foreach (var filter in filtersBatch)
{
FiltersCache[filter.Header.Height] = filter;
}

return filtersBatch.First();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Inlined above. For some reason it feels better to me. Maybe it's because the name of the method does not help me too much in reading the code.

/// <summary>
/// Return the keys to test against the filter depending on the height of the filter and the type of synchronization.
/// </summary>
/// <param name="filterHeight">Height of the filter that needs to be tested.</param>
/// <param name="syncType">First sync of TurboSync, second one, or complete synchronization.</param>
/// <returns>Keys to test against this filter</returns>
/// <seealso href="https://github.com/zkSNACKs/WalletWasabi/issues/10219">TurboSync specification.</seealso>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved up. This is actually quite important and there is a bigger chance that it's read if it is on the "class level".

/// <remarks>Guards <see cref="SynchronizationRequests"/>.</remarks>
private object SynchronizationRequestsLock { get; } = new();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have just one lock here so Lock is the name that we use quite often in such situations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, nice rename. The reason is that when designing this class we had 2 locks but we removed one

}
}
/// <remarks>Internal only to allow modifications in tests.</remarks>
internal Dictionary<uint, FilterModel> FiltersCache { get; } = new();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We only use internal that way, so the comment is useless. Feel free to keep it if you think it's right.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like to stress it because then refactorings are easier but you are as well.

@@ -93,12 +96,11 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kiminuo This is the only change that I do not understand, can you explain it please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's removed because the next line accepts cancellation token as well. So I don't see a reason for having this line.

@kiminuo kiminuo marked this pull request as ready for review December 22, 2023 16:51
Copy link
Collaborator

@adamPetho adamPetho left a comment

Choose a reason for hiding this comment

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

tACK

@kiminuo kiminuo merged commit 0c61acf into WalletWasabi:master Dec 23, 2023
7 checks passed
@kiminuo kiminuo deleted the feature/2023-12-20-WalletFilterProcessor-minor-cleanup branch December 23, 2023 20:17
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