Improve hashchain
MODIFY
WalletWasabi.Tests/LiveServerTests.cs
WalletWasabi.Tests/LiveServerTests.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Threading.Tasks;
using WalletWasabi.Backend.Models.Responses;
using WalletWasabi.Services;
+using WalletWasabi.Stores;
using WalletWasabi.Tests.XunitConfiguration;
using WalletWasabi.TorSocks5;
using WalletWasabi.WebClients.Wasabi;
@@ -49,7 +50,7 @@ namespace WalletWasabi.Tests
{
using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType], Global.TorSocks5Endpoint))
{
- var filterModel = WasabiSynchronizer.GetStartingFilter(Network.GetNetwork(networkType.ToString()));
+ var filterModel = StartingFilters.GetStartingFilter(Network.GetNetwork(networkType.ToString()));
FiltersResponse filtersResponse = await client.GetFiltersAsync(filterModel.BlockHash, 2);

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -305,42 +305,41 @@ namespace WalletWasabi.Tests
{
(string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
- var indexFilePath = Path.Combine(Global.DataDir, nameof(FilterDownloaderTestAsync), $"Index{rpc.Network}.dat");
-
using (var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null))
{
synchronizer.Start(requestInterval: TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), 1000);
+ var blockCount = await rpc.GetBlockCountAsync() + 1; // Plus one because of the zeroth.
// Test initial synchronization.
-
var times = 0;
int filterCount;
- while ((filterCount = await bitcoinStore.IndexStore.CountFiltersAsync()) < 102)
+ while ((filterCount = bitcoinStore.HashChain.HashCount) < blockCount)
{
if (times > 500) // 30 sec
{
- throw new TimeoutException($"{nameof(WasabiSynchronizer)} test timed out. Needed filters: {102}, got only: {filterCount}.");
+ throw new TimeoutException($"{nameof(WasabiSynchronizer)} test timed out. Needed filters: {blockCount}, got only: {filterCount}.");
}
await Task.Delay(100);
times++;
}
+ Assert.Equal(blockCount, bitcoinStore.HashChain.HashCount);
+
// Test later synchronization.
RegTestFixture.BackendRegTestNode.Generate(10);
times = 0;
- while ((filterCount = await bitcoinStore.IndexStore.CountFiltersAsync()) < 112)
+ while ((filterCount = bitcoinStore.HashChain.HashCount) < blockCount + 10)
{
if (times > 500) // 30 sec
{
- throw new TimeoutException($"{nameof(WasabiSynchronizer)} test timed out. Needed filters: {112}, got only: {filterCount}.");
+ throw new TimeoutException($"{nameof(WasabiSynchronizer)} test timed out. Needed filters: {blockCount + 10}, got only: {filterCount}.");
}
await Task.Delay(100);
times++;
}
// Test correct number of filters is received.
- var hundredthHash = await rpc.GetBlockHashAsync(100);
- Assert.Equal(new Height(100), await bitcoinStore.IndexStore.TryGetHeightAsync(hundredthHash));
+ Assert.Equal(blockCount + 10, bitcoinStore.HashChain.HashCount);
// Test filter block hashes are correct.
var filters = (await bitcoinStore.IndexStore.GetFiltersAsync()).ToArray();
@@ -505,7 +504,6 @@ namespace WalletWasabi.Tests
node.Behaviors.Add(new MemPoolBehavior(memPoolService));
// 3. Create wasabi synchronizer service.
- var indexFilePath = Path.Combine(Global.DataDir, nameof(WalletTestsAsync), $"Index{rpc.Network}.dat");
var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
// 4. Create key manager service.
@@ -734,7 +732,6 @@ namespace WalletWasabi.Tests
node.Behaviors.Add(new MemPoolBehavior(memPoolService));
// 3. Create wasabi synchronizer service.
- var indexFilePath = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync), $"Index{rpc.Network}.dat");
var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
// 4. Create key manager service.
@@ -1178,7 +1175,6 @@ namespace WalletWasabi.Tests
node.Behaviors.Add(new MemPoolBehavior(memPoolService));
// 3. Create wasabi synchronizer service.
- var indexFilePath = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync), $"Index{rpc.Network}.dat");
var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
// 4. Create key manager service.
@@ -1342,7 +1338,6 @@ namespace WalletWasabi.Tests
node.Behaviors.Add(new MemPoolBehavior(memPoolService));
// 3. Create wasabi synchronizer service.
- var indexFilePath = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync), $"Index{rpc.Network}.dat");
var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
// 4. Create key manager service.
@@ -1507,10 +1502,7 @@ namespace WalletWasabi.Tests
node.Behaviors.Add(new MemPoolBehavior(memPoolService));
// 3. Create wasabi synchronizer service.
- var indexFilePath = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync),
- $"Index{rpc.Network}.dat");
- var synchronizer =
- new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
+ var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
@@ -1676,10 +1668,7 @@ namespace WalletWasabi.Tests
node.Behaviors.Add(new MemPoolBehavior(memPoolService));
// 3. Create wasabi synchronizer service.
- var indexFilePath = Path.Combine(Global.DataDir, nameof(SendTestsFromHiddenWalletAsync),
- $"Index{rpc.Network}.dat");
- var synchronizer =
- new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
+ var synchronizer = new WasabiSynchronizer(rpc.Network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
// 4. Create key manager service.
var keyManager = KeyManager.CreateNew(out _, password);
@@ -2991,7 +2980,6 @@ namespace WalletWasabi.Tests
{
(string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
- var indexFilePath = Path.Combine(Global.DataDir, nameof(CcjFeeTestsAsync), $"Index{network}.dat");
var synchronizer = new WasabiSynchronizer(network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
synchronizer.Start(requestInterval: TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(5), 10000); // Start wasabi synchronizer service.
@@ -3116,7 +3104,6 @@ namespace WalletWasabi.Tests
{
(string password, RPCClient rpc, Network network, CcjCoordinator coordinator, ServiceConfiguration serviceConfiguration, BitcoinStore bitcoinStore) = await InitializeTestEnvironmentAsync(1);
- var indexFilePath = Path.Combine(Global.DataDir, nameof(CcjClientTestsAsync), $"Index{network}.dat");
var synchronizer = new WasabiSynchronizer(network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
synchronizer.Start(requestInterval: TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(5), 10000); // Start wasabi synchronizer service.
@@ -3299,7 +3286,6 @@ namespace WalletWasabi.Tests
node2.Behaviors.Add(new MemPoolBehavior(memPoolService2));
// 3. Create wasabi synchronizer service.
- var indexFilePath = Path.Combine(Global.DataDir, nameof(CoinJoinMultipleRoundTestsAsync), $"Index{network}.dat");
var synchronizer = new WasabiSynchronizer(network, bitcoinStore, new Uri(RegTestFixture.BackendEndPoint), null);
var indexFilePath2 = Path.Combine(Global.DataDir, nameof(CoinJoinMultipleRoundTestsAsync), $"Index{network}2.dat");

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -333,29 +333,6 @@ namespace WalletWasabi.Services
#region Methods
- public static FilterModel GetStartingFilter(Network network)
- {
- if (network == Network.Main)
- {
- return FilterModel.FromHeightlessLine("0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893:02832810ec08a0", GetStartingHeight(network));
- }
- if (network == Network.TestNet)
- {
- return FilterModel.FromHeightlessLine("00000000000f0d5edcaeba823db17f366be49a80d91d15b77747c2e017b8c20a:017821b8", GetStartingHeight(network));
- }
- if (network == Network.RegTest)
- {
- return FilterModel.FromHeightlessLine("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", GetStartingHeight(network));
- }
- throw new NotSupportedException($"{network} is not supported.");
- }
-
- public FilterModel StartingFilter => GetStartingFilter(Network);
-
- public static Height GetStartingHeight(Network network) => IndexBuilderService.GetStartingHeight(network);
-
- public Height StartingHeight => GetStartingHeight(Network);
-
private void HandleIfGenSocksServFail(Exception ex)
{
// IS GenSocksServFail?

MODIFY
WalletWasabi/Stores/HashChain.cs
WalletWasabi/Stores/HashChain.cs
@@ -18,6 +18,7 @@ namespace WalletWasabi.Stores
private uint256 _tipHash;
private int _serverTipHeight;
private int _hashesLeft;
+ private int _hashesCount;
private SortedDictionary<int, uint256> Chain { get; }
private object Lock { get; }
@@ -74,11 +75,23 @@ namespace WalletWasabi.Stores
}
}
+ public int HashCount
+ {
+ get => _hashesCount;
+ private set
+ {
+ if (_hashesCount != value)
+ {
+ _hashesCount = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HashCount)));
+ }
+ }
+ }
+
public HashChain()
{
Chain = new SortedDictionary<int, uint256>();
Lock = new object();
- ServerTipHeight = 0;
}
public event PropertyChangedEventHandler PropertyChanged;
@@ -90,6 +103,7 @@ namespace WalletWasabi.Stores
Chain.AddOrReplace(height, hash);
TipHeight = height;
TipHash = hash;
+ HashCount = Chain.Count;
SetHashesLeft();
}
}
@@ -109,6 +123,7 @@ namespace WalletWasabi.Stores
var last = Chain.Last();
TipHeight = last.Key;
TipHash = last.Value;
+ HashCount = Chain.Count;
SetHashesLeft();
}
}

MODIFY
WalletWasabi/Stores/IndexStore.cs
WalletWasabi/Stores/IndexStore.cs
@@ -183,17 +183,6 @@ namespace WalletWasabi.Stores
}
}
- public async Task<Height?> TryGetHeightAsync(uint256 blockHash)
- {
- Height? ret = null;
-
- using (await IndexLock.LockAsync())
- {
- ret = Index.FirstOrDefault(x => x.BlockHash == blockHash)?.BlockHeight;
- }
- return ret;
- }
-
public async Task<IEnumerable<FilterModel>> GetFiltersAsync()
{
List<FilterModel> ret = null;
@@ -204,16 +193,5 @@ namespace WalletWasabi.Stores
}
return ret;
}
-
- public async Task<int> CountFiltersAsync()
- {
- int ret;
-
- using (await IndexLock.LockAsync())
- {
- ret = Index.Count;
- }
- return ret;
- }
}
}

Improve hashchain