Better naming and format
RENAME
WalletWasabi/WabiSabi/Backend/Statistics/FeeRateStatRecord.cs
WalletWasabi/WabiSabi/Backend/Statistics/CoinJoinFeeRateStatRecord.cs
@@ -2,7 +2,7 @@ using NBitcoin;
namespace WalletWasabi.WabiSabi.Backend.Statistics;
-public record FeeRateStatRecord(
+public record CoinJoinFeeRateStatRecord(
DateTimeOffset DateTimeOffset,
uint ConfirmationTarget,
FeeRate FeeRate)
@@ -12,7 +12,7 @@ public record FeeRateStatRecord(
return $"{DateTimeOffset.ToUnixTimeSeconds()},{ConfirmationTarget},{(uint)Math.Ceiling(FeeRate.SatoshiPerByte)}";
}
- public static FeeRateStatRecord FromLine(string line)
+ public static CoinJoinFeeRateStatRecord FromLine(string line)
{
var parts = line.Split(",");
var date = DateTimeOffset.FromUnixTimeSeconds(long.Parse(parts[0]));

ADD
WalletWasabi/WabiSabi/Backend/Statistics/CoinJoinFeeRateStatStore.cs
+using NBitcoin;
+using NBitcoin.RPC;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using WalletWasabi.Bases;
+using WalletWasabi.BitcoinCore.Rpc;
+
+namespace WalletWasabi.WabiSabi.Backend.Statistics;
+
+public class CoinJoinFeeRateStatStore : PeriodicRunner
+{
+ private const int MaximumDaysToStore = 30;
+ private List<CoinJoinFeeRateStatRecord> CoinJoinFeeRateStatRecords { get; }
+
+ public CoinJoinFeeRateStatStore(WabiSabiConfig config, IRPCClient rpc, IEnumerable<CoinJoinFeeRateStatRecord> feeRateStatRecords) :
+ base(TimeSpan.FromMinutes(10))
+ {
+ Config = config;
+ Rpc = rpc;
+ CoinJoinFeeRateStatRecords = new(feeRateStatRecords.OrderBy(x => x.DateTimeOffset));
+ }
+
+ private WabiSabiConfig Config { get; }
+ private IRPCClient Rpc { get; }
+
+ public event EventHandler<CoinJoinFeeRateStatRecord>? NewStat;
+
+ protected override async Task ActionAsync(CancellationToken cancel)
+ {
+ var feeRate = (await Rpc.EstimateSmartFeeAsync((int)Config.ConfirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, cancel).ConfigureAwait(false)).FeeRate;
+
+ CoinJoinFeeRateStatRecord record = new(DateTimeOffset.UtcNow, Config.ConfirmationTarget, feeRate);
+ Add(record);
+ NewStat?.Invoke(this, record);
+ }
+
+ public void Add(CoinJoinFeeRateStatRecord feeRateStatRecord)
+ {
+ CoinJoinFeeRateStatRecords.Add(feeRateStatRecord);
+
+ // Prune old items.
+ DateTimeOffset removeBefore = DateTimeOffset.UtcNow - TimeSpan.FromDays(MaximumDaysToStore);
+ while (CoinJoinFeeRateStatRecords.Any() && CoinJoinFeeRateStatRecords[0].DateTimeOffset < removeBefore)
+ {
+ CoinJoinFeeRateStatRecords.RemoveAt(0);
+ }
+ }
+
+ public FeeRate GetAvarage(TimeSpan timeFrame)
+ {
+ var from = DateTimeOffset.UtcNow - timeFrame;
+ return new FeeRate(CoinJoinFeeRateStatRecords.Where(x => x.DateTimeOffset >= from).Average(x => x.FeeRate.SatoshiPerByte));
+ }
+
+ public static CoinJoinFeeRateStatStore LoadFromFile(string filePath, WabiSabiConfig config, IRPCClient rpc)
+ {
+ var now = DateTimeOffset.UtcNow;
+ var from = now - TimeSpan.FromDays(MaximumDaysToStore);
+
+ var records = !File.Exists(filePath) ?
+ Enumerable.Empty<CoinJoinFeeRateStatRecord>() :
+ File.ReadAllLines(filePath)
+ .Select(x => CoinJoinFeeRateStatRecord.FromLine(x))
+ .Where(x => x.DateTimeOffset > from);
+
+ var store = new CoinJoinFeeRateStatStore(config, rpc, records);
+
+ return store;
+ }
+}

DELETE
WalletWasabi/WabiSabi/Backend/Statistics/FeeRateStatStore.cs
-using NBitcoin;
-using NBitcoin.RPC;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using WalletWasabi.Bases;
-using WalletWasabi.BitcoinCore.Rpc;
-
-namespace WalletWasabi.WabiSabi.Backend.Statistics;
-
-public class FeeRateStatStore : PeriodicRunner
-{
- private const int MaximumDaysToStore = 30;
- private List<FeeRateStatRecord> FeeRateStatRecords { get; }
-
- public FeeRateStatStore(WabiSabiConfig config, IRPCClient rpc, IEnumerable<FeeRateStatRecord> feeRateStatRecords) :
- base(TimeSpan.FromMinutes(10))
- {
- Config = config;
- Rpc = rpc;
- FeeRateStatRecords = new(feeRateStatRecords.OrderBy(x => x.DateTimeOffset));
- }
-
- public WabiSabiConfig Config { get; }
- public IRPCClient Rpc { get; }
-
- public event EventHandler<FeeRateStatRecord>? NewStat;
-
- protected override async Task ActionAsync(CancellationToken cancel)
- {
- var feeRate = (await Rpc.EstimateSmartFeeAsync((int)Config.ConfirmationTarget, EstimateSmartFeeMode.Conservative, simulateIfRegTest: true, cancel).ConfigureAwait(false)).FeeRate;
-
- FeeRateStatRecord record = new(DateTimeOffset.UtcNow, Config.ConfirmationTarget, feeRate);
- Add(record);
- NewStat?.Invoke(this, record);
- }
-
- public void Add(FeeRateStatRecord feeRateStatRecord)
- {
- DateTimeOffset now = DateTimeOffset.UtcNow;
-
- FeeRateStatRecords.Add(feeRateStatRecord);
-
- // Prune old items.
- DateTimeOffset removeBefore = now - TimeSpan.FromDays(MaximumDaysToStore);
- while (FeeRateStatRecords.Any() && FeeRateStatRecords[0].DateTimeOffset < removeBefore)
- {
- FeeRateStatRecords.RemoveAt(0);
- }
- }
-
- public FeeRate GetAvarage(TimeSpan timeFrame)
- {
- var from = DateTimeOffset.UtcNow - timeFrame;
- return new FeeRate(FeeRateStatRecords.Where(x => x.DateTimeOffset >= from).Average(x => x.FeeRate.SatoshiPerByte));
- }
-
- public static FeeRateStatStore LoadFromFile(string filePath, WabiSabiConfig config, IRPCClient rpc)
- {
- var now = DateTimeOffset.UtcNow;
- var from = now - TimeSpan.FromDays(MaximumDaysToStore);
-
- var records = !File.Exists(filePath) ?
- Enumerable.Empty<FeeRateStatRecord>() :
- File.ReadAllLines(filePath)
- .Select(x => FeeRateStatRecord.FromLine(x))
- .Where(x => x.DateTimeOffset > from);
-
- var store = new FeeRateStatStore(config, rpc, records);
-
- return store;
- }
-}

MODIFY
WalletWasabi/WabiSabi/CoordinatorParameters.cs
WalletWasabi/WabiSabi/CoordinatorParameters.cs
@@ -38,7 +38,7 @@ public class CoordinatorParameters
/// <summary>
/// File that is storing the feeRate statistics.
/// </summary>
- public string FeeRateStatStoreFilePath => Path.Combine(CoordinatorDataDir, "FeeRateStatStore.txt");
+ public string CoinJoinFeeRateStatStoreFilePath => Path.Combine(CoordinatorDataDir, "CoinJoinFeeRateStatStore.txt");
/// <summary>
/// Runtime adjustable configuration of the coordinator.

MODIFY
WalletWasabi/WabiSabi/WabiSabiCoordinator.cs
WalletWasabi/WabiSabi/WabiSabiCoordinator.cs
@@ -31,8 +31,8 @@ public class WabiSabiCoordinator : BackgroundService
Arena = new(parameters.RoundProgressSteppingPeriod, rpc.Network, Config, rpc, Warden.Prison, inMemoryCoinJoinIdStore, transactionArchiver);
Arena.CoinJoinBroadcast += Arena_CoinJoinBroadcast;
- FeeRateStatStore = FeeRateStatStore.LoadFromFile(parameters.FeeRateStatStoreFilePath, Config, rpc);
- FeeRateStatStore.NewStat += FeeRateStatStore_NewStat;
+ CoinJoinFeeRateStatStore = CoinJoinFeeRateStatStore.LoadFromFile(parameters.CoinJoinFeeRateStatStoreFilePath, Config, rpc);
+ CoinJoinFeeRateStatStore.NewStat += FeeRateStatStore_NewStat;
}
public ConfigWatcher ConfigWatcher { get; }
@@ -41,7 +41,7 @@ public class WabiSabiCoordinator : BackgroundService
public CoordinatorParameters Parameters { get; }
public Arena Arena { get; }
- public FeeRateStatStore FeeRateStatStore { get; }
+ public CoinJoinFeeRateStatStore CoinJoinFeeRateStatStore { get; }
public WabiSabiConfig Config => Parameters.RuntimeCoordinatorConfig;
@@ -55,14 +55,14 @@ public class WabiSabiCoordinator : BackgroundService
File.AppendAllLines(Parameters.CoinJoinIdStoreFilePath, new[] { e.GetHash().ToString() });
}
- private void FeeRateStatStore_NewStat(object? sender, FeeRateStatRecord record)
+ private void FeeRateStatStore_NewStat(object? sender, CoinJoinFeeRateStatRecord record)
{
- if (!File.Exists(Parameters.FeeRateStatStoreFilePath))
+ if (!File.Exists(Parameters.CoinJoinFeeRateStatStoreFilePath))
{
- IoHelpers.EnsureContainingDirectoryExists(Parameters.FeeRateStatStoreFilePath);
+ IoHelpers.EnsureContainingDirectoryExists(Parameters.CoinJoinFeeRateStatStoreFilePath);
}
- File.AppendAllLines(Parameters.FeeRateStatStoreFilePath, new[] { record.ToLine() });
+ File.AppendAllLines(Parameters.CoinJoinFeeRateStatStoreFilePath, new[] { record.ToLine() });
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@@ -71,7 +71,7 @@ public class WabiSabiCoordinator : BackgroundService
await Warden.StartAsync(stoppingToken).ConfigureAwait(false);
await Arena.StartAsync(stoppingToken).ConfigureAwait(false);
- await FeeRateStatStore.StartAsync(stoppingToken).ConfigureAwait(false);
+ await CoinJoinFeeRateStatStore.StartAsync(stoppingToken).ConfigureAwait(false);
}
public override async Task StopAsync(CancellationToken cancellationToken)
@@ -82,12 +82,12 @@ public class WabiSabiCoordinator : BackgroundService
await ConfigWatcher.StopAsync(cancellationToken).ConfigureAwait(false);
await Warden.StopAsync(cancellationToken).ConfigureAwait(false);
- await FeeRateStatStore.StopAsync(cancellationToken).ConfigureAwait(false);
+ await CoinJoinFeeRateStatStore.StopAsync(cancellationToken).ConfigureAwait(false);
}
public override void Dispose()
{
- FeeRateStatStore.NewStat -= FeeRateStatStore_NewStat;
+ CoinJoinFeeRateStatStore.NewStat -= FeeRateStatStore_NewStat;
Arena.CoinJoinBroadcast -= Arena_CoinJoinBroadcast;
ConfigWatcher.Dispose();
Warden.Dispose();

Better naming and format