From 88ab41211851f7c9337bbfd99db8a06c27f1bd2c Mon Sep 17 00:00:00 2001 From: Lucas Ontivero Date: Sat, 7 Sep 2024 16:00:17 -0300 Subject: [PATCH] Pass index file path by parameter (#13368) Co-authored-by: Turbolay --- WalletWasabi.Backend/Global.cs | 2 +- .../RegressionTests/BackendTests.cs | 2 +- .../BitcoinCore/IndexBuilderServiceTests.cs | 16 ++++++++-------- .../BlockFilters/IndexBuilderService.cs | 4 +--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/WalletWasabi.Backend/Global.cs b/WalletWasabi.Backend/Global.cs index 6a098b45c15..3b183259bc6 100644 --- a/WalletWasabi.Backend/Global.cs +++ b/WalletWasabi.Backend/Global.cs @@ -43,7 +43,7 @@ public Global(string dataDir, IRPCClient rpcClient, Config config) // Initialize index building var indexBuilderServiceDir = Path.Combine(DataDir, "IndexBuilderService"); var indexFilePath = Path.Combine(indexBuilderServiceDir, $"Index{RpcClient.Network}.dat"); - IndexBuilderService = new(RpcClient, HostedServices.Get()); + IndexBuilderService = new(RpcClient, HostedServices.Get(), indexFilePath); } public string DataDir { get; } diff --git a/WalletWasabi.Tests/RegressionTests/BackendTests.cs b/WalletWasabi.Tests/RegressionTests/BackendTests.cs index 73afb50fbc5..d3a20d085cc 100644 --- a/WalletWasabi.Tests/RegressionTests/BackendTests.cs +++ b/WalletWasabi.Tests/RegressionTests/BackendTests.cs @@ -244,7 +244,7 @@ public async Task FilterBuilderTestAsync() var indexBuilderServiceDir = Helpers.Common.GetWorkDir(); var indexFilePath = Path.Combine(indexBuilderServiceDir, $"Index{rpc.Network}.dat"); - IndexBuilderService indexBuilderService = new(rpc, global.HostedServices.Get()); + IndexBuilderService indexBuilderService = new(rpc, global.HostedServices.Get(), "filters.txt"); try { indexBuilderService.Synchronize(); diff --git a/WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs b/WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs index 14c4e89237e..1b8f80f23fa 100644 --- a/WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs +++ b/WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs @@ -28,7 +28,7 @@ public async Task SegwitTaprootUnsynchronizedBitcoinNodeAsync() }), }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); @@ -55,7 +55,7 @@ public async Task SegwitTaprootStalledBitcoinNodeAsync() } }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); @@ -86,7 +86,7 @@ public async Task SegwitTaprootSynchronizingBitcoinNodeAsync() OnGetVerboseBlockAsync = (hash) => Task.FromResult(blockchain.Single(x => x.Hash == hash)) }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); @@ -156,7 +156,7 @@ public async Task SegwitTaprootSynchronizedBitcoinNodeAsync() OnGetVerboseBlockAsync = (hash) => Task.FromResult(blockchain.Single(x => x.Hash == hash)) }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); @@ -182,7 +182,7 @@ public async Task TaprootUnsynchronizedBitcoinNodeAsync() }), }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); @@ -209,7 +209,7 @@ public async Task TaprootStalledBitcoinNodeAsync() } }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); @@ -240,7 +240,7 @@ public async Task TaprootSynchronizingBitcoinNodeAsync() OnGetVerboseBlockAsync = (hash) => Task.FromResult(blockchain.Single(x => x.Hash == hash)) }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); @@ -268,7 +268,7 @@ public async Task TaprootSynchronizedBitcoinNodeAsync() OnGetVerboseBlockAsync = (hash) => Task.FromResult(blockchain.Single(x => x.Hash == hash)) }; using var blockNotifier = new BlockNotifier(rpc); - var indexer = new IndexBuilderService(rpc, blockNotifier); + var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt"); indexer.Synchronize(); diff --git a/WalletWasabi/Blockchain/BlockFilters/IndexBuilderService.cs b/WalletWasabi/Blockchain/BlockFilters/IndexBuilderService.cs index b73c133f5c8..a692d25248f 100644 --- a/WalletWasabi/Blockchain/BlockFilters/IndexBuilderService.cs +++ b/WalletWasabi/Blockchain/BlockFilters/IndexBuilderService.cs @@ -29,12 +29,10 @@ public class IndexBuilderService private long _workerCount; - public IndexBuilderService(IRPCClient rpc, BlockNotifier blockNotifier) + public IndexBuilderService(IRPCClient rpc, BlockNotifier blockNotifier, string indexFilePath) { RpcClient = Guard.NotNull(nameof(rpc), rpc); BlockNotifier = Guard.NotNull(nameof(blockNotifier), blockNotifier); - var indexBuilderServiceDir = Path.Combine(".", "IndexBuilderService"); - var indexFilePath = Path.Combine(indexBuilderServiceDir, $"Index{rpc.Network}.dat"); IndexFilePath = Guard.NotNullOrEmptyOrWhitespace(nameof(indexFilePath), indexFilePath); StartingHeight = SmartHeader.GetStartingHeader(RpcClient.Network).Height;