Bring Blocks under BitcoinStore umbrella.
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -106,8 +106,9 @@ namespace WalletWasabi.Gui
var transactionStore = new AllTransactionStore(networkWorkFolderPath, Network);
var indexStore = new IndexStore(Path.Combine(networkWorkFolderPath, "IndexStore"), Network, new SmartHeaderChain());
var mempoolService = new MempoolService();
+ var blocks = new FileSystemBlockRepository(Path.Combine(networkWorkFolderPath, "Blocks"), Network);
- BitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService);
+ BitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService, blocks);
SingleInstanceChecker = new SingleInstanceChecker(Network);
@@ -153,7 +154,6 @@ namespace WalletWasabi.Gui
AddressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{Network}.dat");
var addrManTask = InitializeAddressManagerBehaviorAsync();
- var blocksFolderPath = Path.Combine(DataDir, "Blocks", Network.ToString());
var userAgent = Constants.UserAgents.RandomElement();
var connectionParameters = new NodeConnectionParameters { UserAgent = userAgent };
@@ -371,7 +371,7 @@ namespace WalletWasabi.Gui
new SmartBlockProvider(
new P2pBlockProvider(Nodes, BitcoinCoreNode, Synchronizer, Config.ServiceConfiguration, Network),
Cache),
- new FileSystemBlockRepository(DataDir, blocksFolderPath, Network));
+ BitcoinStore.Blocks);
#endregion Blocks provider

MODIFY
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
WalletWasabi.Tests/IntegrationTests/P2pTests.cs
@@ -61,12 +61,12 @@ namespace WalletWasabi.Tests.IntegrationTests
var indexStore = new IndexStore(Path.Combine(dir, "indexStore"), network, new SmartHeaderChain());
var transactionStore = new AllTransactionStore(Path.Combine(dir, "transactionStore"), network);
var mempoolService = new MempoolService();
- BitcoinStore bitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService);
+ var blocks = new FileSystemBlockRepository(Path.Combine(dir, "blocks"), network);
+ BitcoinStore bitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService, blocks);
await bitcoinStore.InitializeAsync();
var addressManagerFolderPath = Path.Combine(dataDir, "AddressManager");
var addressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{network}.dat");
- var blocksFolderPath = Path.Combine(dataDir, "Blocks", network.ToString());
var connectionParameters = new NodeConnectionParameters();
AddressManager addressManager = null;
try
@@ -103,7 +103,7 @@ namespace WalletWasabi.Tests.IntegrationTests
ServiceConfiguration serviceConfig = new ServiceConfiguration(MixUntilAnonymitySet.PrivacyLevelStrong.ToString(), 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold));
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, syncer, serviceConfig, network),
- new FileSystemBlockRepository(dataDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
using Wallet wallet = Wallet.CreateAndRegisterServices(
network,
@@ -115,7 +115,7 @@ namespace WalletWasabi.Tests.IntegrationTests
new ServiceConfiguration(MixUntilAnonymitySet.PrivacyLevelStrong.ToString(), 2, 21, 50, new IPEndPoint(IPAddress.Loopback, network.DefaultPort), Money.Coins(Constants.DefaultDustThreshold)),
syncer,
blockProvider);
- Assert.True(Directory.Exists(blocksFolderPath));
+ Assert.True(Directory.Exists(blocks.BlocksFolderPath));
try
{
@@ -144,7 +144,7 @@ namespace WalletWasabi.Tests.IntegrationTests
var hashArray = blocksToDownload.ToArray();
foreach (var block in await Task.WhenAll(downloadTasks))
{
- Assert.True(File.Exists(Path.Combine(blocksFolderPath, hashArray[i].ToString())));
+ Assert.True(File.Exists(Path.Combine(blocks.BlocksFolderPath, hashArray[i].ToString())));
i++;
}
@@ -162,9 +162,9 @@ namespace WalletWasabi.Tests.IntegrationTests
await wallet.StopAsync(CancellationToken.None);
}
- if (Directory.Exists(blocksFolderPath))
+ if (Directory.Exists(blocks.BlocksFolderPath))
{
- Directory.Delete(blocksFolderPath, recursive: true);
+ Directory.Delete(blocks.BlocksFolderPath, recursive: true);
}
IoHelpers.EnsureContainingDirectoryExists(addressManagerFilePath);

MODIFY
WalletWasabi.Tests/RegressionTests/BuildTests.cs
WalletWasabi.Tests/RegressionTests/BuildTests.cs
@@ -62,10 +62,9 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var blocksFolderPath = Path.Combine(workDir, "Blocks", network.ToString());
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;
@@ -226,10 +225,9 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var blocksFolderPath = Path.Combine(workDir, "Blocks", network.ToString());
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
var walletManager = new WalletManager(network, new WalletDirectories(workDir));
walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -1384,15 +1384,13 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var blocksFolderPath = Path.Combine(workDir, "Blocks", network.ToString());
-
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
CachedBlockProvider blockProvider2 = new CachedBlockProvider(
new P2pBlockProvider(nodes2, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;

MODIFY
WalletWasabi.Tests/RegressionTests/Common.cs
WalletWasabi.Tests/RegressionTests/Common.cs
@@ -96,7 +96,8 @@ namespace WalletWasabi.Tests.RegressionTests
var indexStore = new IndexStore(Path.Combine(dir, "indexStore"), network, new SmartHeaderChain());
var transactionStore = new AllTransactionStore(Path.Combine(dir, "transactionStore"), network);
var mempoolService = new MempoolService();
- var bitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService);
+ var blocks = new FileSystemBlockRepository(Path.Combine(dir, "blocks"), network);
+ var bitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService, blocks);
await bitcoinStore.InitializeAsync();
return ("password", global.RpcClient, network, global.Coordinator, serviceConfiguration, bitcoinStore, global);
}

MODIFY
WalletWasabi.Tests/RegressionTests/SendTests.cs
WalletWasabi.Tests/RegressionTests/SendTests.cs
@@ -60,11 +60,10 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var blocksFolderPath = Path.Combine(workDir, "Blocks", network.ToString());
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
var walletManager = new WalletManager(network, new WalletDirectories(workDir));
walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
@@ -540,11 +539,10 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var blocksFolderPath = Path.Combine(workDir, "Blocks", network.ToString());
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
var walletManager = new WalletManager(network, new WalletDirectories(workDir));
walletManager.RegisterServices(bitcoinStore, synchronizer, nodes, serviceConfiguration, synchronizer, blockProvider);
@@ -714,11 +712,10 @@ namespace WalletWasabi.Tests.RegressionTests
// 5. Create wallet service.
var workDir = Common.GetWorkDir();
- var blocksFolderPath = Path.Combine(workDir, "Blocks", network.ToString());
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;

MODIFY
WalletWasabi.Tests/RegressionTests/WalletTests.cs
WalletWasabi.Tests/RegressionTests/WalletTests.cs
@@ -279,11 +279,10 @@ namespace WalletWasabi.Tests.RegressionTests
// 4. Create wallet service.
var workDir = Common.GetWorkDir();
- var blocksFolderPath = Path.Combine(workDir, "Blocks", network.ToString());
CachedBlockProvider blockProvider = new CachedBlockProvider(
new P2pBlockProvider(nodes, null, synchronizer, serviceConfiguration, network),
- new FileSystemBlockRepository(workDir, blocksFolderPath, network));
+ bitcoinStore.Blocks);
using var wallet = Wallet.CreateAndRegisterServices(network, bitcoinStore, keyManager, synchronizer, nodes, workDir, serviceConfiguration, synchronizer, blockProvider);
wallet.NewFilterProcessed += Common.Wallet_NewFilterProcessed;

MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/P2pBasedTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/P2pBasedTests.cs
@@ -14,6 +14,7 @@ using WalletWasabi.Helpers;
using WalletWasabi.Services;
using WalletWasabi.Stores;
using WalletWasabi.Tests.Helpers;
+using WalletWasabi.Wallets;
using Xunit;
namespace WalletWasabi.Tests.UnitTests.BitcoinCore
@@ -37,7 +38,8 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
var indexStore = new IndexStore(Path.Combine(dir, "indexStore"), network, new SmartHeaderChain());
var transactionStore = new AllTransactionStore(Path.Combine(dir, "transactionStore"), network);
var mempoolService = new MempoolService();
- var bitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService);
+ var blocks = new FileSystemBlockRepository(Path.Combine(dir, "blocks"), network);
+ var bitcoinStore = new BitcoinStore(indexStore, transactionStore, mempoolService, blocks);
await bitcoinStore.InitializeAsync();
await rpc.GenerateAsync(101);

MODIFY
WalletWasabi/Stores/BitcoinStore.cs
WalletWasabi/Stores/BitcoinStore.cs
+using NBitcoin;
using System.IO;
using System.Threading.Tasks;
using WalletWasabi.Blockchain.Blocks;
@@ -6,6 +7,7 @@ using WalletWasabi.Blockchain.P2p;
using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
+using WalletWasabi.Wallets;
namespace WalletWasabi.Stores
{
@@ -18,11 +20,13 @@ namespace WalletWasabi.Stores
public BitcoinStore(
IndexStore indexStore,
AllTransactionStore transactionStore,
- MempoolService mempoolService)
+ MempoolService mempoolService,
+ IRepository<uint256, Block> blocks)
{
IndexStore = indexStore;
TransactionStore = transactionStore;
MempoolService = mempoolService;
+ Blocks = blocks;
}
public bool IsInitialized { get; private set; }
@@ -31,6 +35,7 @@ namespace WalletWasabi.Stores
public AllTransactionStore TransactionStore { get; }
public SmartHeaderChain SmartHeaderChain => IndexStore.SmartHeaderChain;
public MempoolService MempoolService { get; }
+ public IRepository<uint256, Block> Blocks { get; }
/// <summary>
/// This should not be a property, but a creator function, because it'll be cloned left and right by NBitcoin later.

MODIFY
WalletWasabi/Wallets/FileSystemBlockRepository.cs
WalletWasabi/Wallets/FileSystemBlockRepository.cs
@@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using WalletWasabi.Helpers;
using WalletWasabi.Logging;
namespace WalletWasabi.Wallets
@@ -18,25 +19,20 @@ namespace WalletWasabi.Wallets
{
private const double MegaByte = 1024 * 1024;
- /// <summary>
- /// Creates new instance.
- /// </summary>
- /// <param name="dataDir">Application data directory.</param>
- /// <param name="blocksFolderPath">Folder where to store blocks as files.</param>
- /// <param name="network">Bitcoin network.</param>
- /// <param name="targetBlocksFolderSizeMb"></param>
- public FileSystemBlockRepository(string dataDir, string blocksFolderPath, Network network, long targetBlocksFolderSizeMb = 300)
+ public FileSystemBlockRepository(string blocksFolderPath, Network network, long targetBlocksFolderSizeMb = 300)
+ {
+ // Migrate files one by one from the old path to the new path.
+ using (BenchmarkLogger.Measure())
{
- DataDir = dataDir;
BlocksFolderPath = blocksFolderPath;
Network = network;
CreateFolders();
EnsureBackwardsCompatibility();
Prune(targetBlocksFolderSizeMb);
}
+ }
public string BlocksFolderPath { get; }
- private string DataDir { get; }
private Network Network { get; }
private AsyncLock BlockFolderLock { get; } = new AsyncLock();
@@ -50,16 +46,17 @@ namespace WalletWasabi.Wallets
try
{
// Before Wasabi 1.1.13
- var wrongBlockFolderPath = Path.Combine(DataDir, $"Blocks{Network}");
+ var wrongGlobalBlockFodlerPath = Path.Combine(EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Client")), "Blocks");
+ var wrongBlockFolderPaths = new[]
+ {
+ Path.Combine(EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Client")), $"Blocks{Network}"),
+ Path.Combine(wrongGlobalBlockFodlerPath, Network.Name)
+ };
- // Check whether old folder exists.
- if (Directory.Exists(wrongBlockFolderPath))
+ foreach (var wrongBlockFolderPath in wrongBlockFolderPaths.Where(x => Directory.Exists(x)))
{
Logger.LogTrace($"Initiate migration of '{wrongBlockFolderPath}'");
- // Migrate files one by one from the old path to the new path.
- using (BenchmarkLogger.Measure())
- {
int cntSuccess = 0;
int cntRedundant = 0;
int cntFailure = 0;
@@ -113,6 +110,14 @@ namespace WalletWasabi.Wallets
Logger.LogInfo($"Deleted '{wrongBlockFolderPath}' folder.");
}
+
+ if (Directory.Exists(wrongGlobalBlockFodlerPath))
+ {
+ // If all networks successfully migrated, too, then delete the transactions folder, too.
+ if (!Directory.EnumerateFileSystemEntries(wrongGlobalBlockFodlerPath).Any())
+ {
+ Directory.Delete(wrongGlobalBlockFodlerPath, recursive: true);
+ }
}
}
catch (Exception ex)
@@ -133,8 +138,6 @@ namespace WalletWasabi.Wallets
Logger.LogTrace($"> {nameof(maxFolderSizeMb)}={maxFolderSizeMb}");
try
- {
- using (BenchmarkLogger.Measure())
{
List<FileInfo> fileInfoList = Directory.EnumerateFiles(BlocksFolderPath).Select(x => new FileInfo(x)).ToList();
@@ -174,7 +177,6 @@ namespace WalletWasabi.Wallets
Logger.LogInfo($"Blocks folder was over {maxFolderSizeMb} MB. Deleted {cntPruned} blocks.");
}
}
- }
catch (Exception ex)
{
Logger.LogWarning(ex);
@@ -284,18 +286,19 @@ namespace WalletWasabi.Wallets
private void CreateFolders()
{
- if (Directory.Exists(BlocksFolderPath))
+ try
{
- if (Network == Network.RegTest)
+ if (Directory.Exists(BlocksFolderPath) && Network == Network.RegTest)
{
Directory.Delete(BlocksFolderPath, true);
- Directory.CreateDirectory(BlocksFolderPath);
}
}
- else
+ catch (Exception ex)
{
- Directory.CreateDirectory(BlocksFolderPath);
+ Logger.LogDebug(ex);
}
+
+ IoHelpers.EnsureDirectoryExists(BlocksFolderPath);
}
}
}

Bring Blocks under BitcoinStore umbrella.