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

[refactoring] FeeStrategy implementation #11651

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented Oct 8, 2023

Simplify FeeStrategy implementation and remove 2 warnings in the process.

Easy to review commit by commit.

@kiminuo kiminuo marked this pull request as draft October 8, 2023 07:55
@kiminuo kiminuo force-pushed the feature/2023-10-08-FeeStrategy-refactoring branch from 8c4da97 to 0418f89 Compare October 8, 2023 07:57
}

public static FeeStrategy TwentyMinutesConfirmationTargetStrategy { get; } = CreateFromConfirmationTarget(Constants.TwentyMinutesConfirmationTarget);
public static FeeStrategy OneDayConfirmationTargetStrategy { get; } = CreateFromConfirmationTarget(Constants.OneDayConfirmationTarget);
public static FeeStrategy SevenDaysConfirmationTargetStrategy { get; } = CreateFromConfirmationTarget(Constants.SevenDaysConfirmationTarget);

public static FeeStrategy CreateFromConfirmationTarget(int confirmationTarget) => new(FeeStrategyType.Target, confirmationTarget: confirmationTarget, feeRate: null);
public static FeeStrategy CreateFromConfirmationTarget(int confirmationTarget)
=> new(confirmationTarget: confirmationTarget);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just to easily compare with L67.

using WalletWasabi.Helpers;

namespace WalletWasabi.Blockchain.TransactionBuilding;

public class FeeStrategy
{
public static readonly FeeRate MinimumFeeRate = new(1m);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Avoids allocations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Only one reference to MinimumFeeRate. Maybe it could be private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea is that one can compare to that number if FeeRate strategy is used. You are right that it's not used at the moment. It's a constant in a way so I think it's OK to be public.

If you feel strongly against it, please change it in a follow-up PR.

private int? _target;
private FeeRate? _rate;

private FeeStrategy(FeeStrategyType type, int? confirmationTarget, FeeRate? feeRate)
private FeeStrategy(int confirmationTarget)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are two FeeStrategyTypes, so 2 ctors is a simple approach to model that.

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BOM?

@kiminuo kiminuo force-pushed the feature/2023-10-08-FeeStrategy-refactoring branch from 2a1a280 to 0796e60 Compare October 8, 2023 08:15
@kiminuo kiminuo requested a review from adamPetho October 8, 2023 19:27
@kiminuo kiminuo marked this pull request as ready for review October 8, 2023 19:27
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.

Looks much better!

tACK, everything seems to work just as before.

using WalletWasabi.Helpers;

namespace WalletWasabi.Blockchain.TransactionBuilding;

public class FeeStrategy
{
public static readonly FeeRate MinimumFeeRate = new(1m);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Only one reference to MinimumFeeRate. Maybe it could be private?

@adamPetho adamPetho requested a review from Szpoti October 9, 2023 09:27
@kiminuo kiminuo merged commit f060050 into WalletWasabi:master Oct 9, 2023
6 of 7 checks passed
@adamPetho adamPetho removed the request for review from Szpoti October 9, 2023 09:27
@kiminuo
Copy link
Collaborator Author

kiminuo commented Oct 9, 2023

Ha, you asked @Szpoti for review. He can certainly review the PR and I can address potential feedback in a follow-up PR.

@kiminuo kiminuo deleted the feature/2023-10-08-FeeStrategy-refactoring branch October 9, 2023 09:28
Copy link
Collaborator

@Szpoti Szpoti left a comment

Choose a reason for hiding this comment

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

late ACK,
Looks nice, my only nit is the same for making MinimumFeeRate private.

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