Skip to content

Commit

Permalink
Replace IndexDownloader with WasabiSynchronizer
Browse files Browse the repository at this point in the history
  • Loading branch information
nopara73 committed Dec 19, 2018
1 parent 6976451 commit 19962e5
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 635 deletions.
6 changes: 3 additions & 3 deletions WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public CoinViewModel(SmartCoin model)
this.RaisePropertyChanged(nameof(Unspent));
});

this.WhenAnyValue(x => x.Status).Subscribe(_ =>
this.WhenAnyValue(x => x.Status).Subscribe(_ =>
{
this.RaisePropertyChanged(nameof(ToolTip));
});

Global.IndexDownloader.WhenAnyValue(x => x.BestHeight).ObserveOn(RxApp.MainThreadScheduler).Subscribe(_ =>
Global.Synchronizer.WhenAnyValue(x => x.BestBlockchainHeight).ObserveOn(RxApp.MainThreadScheduler).Subscribe(_ =>
{
RefreshSmartCoinStatus();
this.RaisePropertyChanged(nameof(Confirmations));
Expand All @@ -86,7 +86,7 @@ private void ChaumianClient_StateUpdated(object sender, EventArgs e)
public string Address => Model.ScriptPubKey.GetDestinationAddress(Global.Network).ToString();

public int Confirmations => Model.Height.Type == HeightType.Chain
? Global.IndexDownloader.BestHeight.Value - Model.Height.Value + 1
? Global.Synchronizer.BestBlockchainHeight.Value - Model.Height.Value + 1
: 0;

public bool IsSelected
Expand Down
14 changes: 7 additions & 7 deletions WalletWasabi.Gui/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static string TorLogsFile
public static AddressManager AddressManager { get; private set; }
public static MemPoolService MemPoolService { get; private set; }
public static NodesGroup Nodes { get; private set; }
public static IndexDownloader IndexDownloader { get; private set; }
public static WasabiSynchronizer Synchronizer { get; private set; }
public static CcjClient ChaumianClient { get; private set; }
public static WalletService WalletService { get; private set; }
public static Node RegTestMemPoolServingNode { get; private set; }
Expand Down Expand Up @@ -218,9 +218,9 @@ public static void InitializeNoWallet()
RegTestMemPoolServingNode = null;
}

IndexDownloader = new IndexDownloader(Network, IndexFilePath, Config.GetCurrentBackendUri(), Config.GetTorSocks5EndPoint());
Synchronizer = new WasabiSynchronizer(Network, IndexFilePath, Config.GetCurrentBackendUri(), Config.GetTorSocks5EndPoint());

UpdateChecker = new UpdateChecker(IndexDownloader.WasabiClient);
UpdateChecker = new UpdateChecker(Synchronizer.WasabiClient);

Nodes.Connect();
Logger.LogInfo("Start connecting to nodes...");
Expand All @@ -231,7 +231,7 @@ public static void InitializeNoWallet()
Logger.LogInfo("Start connecting to mempool serving regtest node...");
}

IndexDownloader.Synchronize(requestInterval: TimeSpan.FromSeconds(21));
Synchronizer.Start(requestInterval: TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(5), 1000);
Logger.LogInfo("Start synchronizing filters...");
}

Expand All @@ -240,7 +240,7 @@ public static void InitializeNoWallet()
public static async Task InitializeWalletServiceAsync(KeyManager keyManager)
{
ChaumianClient = new CcjClient(Network, BlindingPubKey, keyManager, Config.GetCurrentBackendUri(), Config.GetTorSocks5EndPoint());
WalletService = new WalletService(keyManager, IndexDownloader, ChaumianClient, MemPoolService, Nodes, DataDir);
WalletService = new WalletService(keyManager, Synchronizer, ChaumianClient, MemPoolService, Nodes, DataDir);

ChaumianClient.Start(0, 3);
Logger.LogInfo("Start Chaumian CoinJoin service...");
Expand Down Expand Up @@ -331,8 +331,8 @@ public static async Task DisposeAsync()
UpdateChecker?.Dispose();
Logger.LogInfo($"{nameof(UpdateChecker)} is stopped.", nameof(Global));

IndexDownloader?.Dispose();
Logger.LogInfo($"{nameof(IndexDownloader)} is stopped.", nameof(Global));
Synchronizer?.Dispose();
Logger.LogInfo($"{nameof(Synchronizer)} is stopped.", nameof(Global));

IoHelpers.EnsureContainingDirectoryExists(AddressManagerFilePath);
AddressManager?.SavePeerFile(AddressManagerFilePath, Config.Network);
Expand Down
6 changes: 3 additions & 3 deletions WalletWasabi.Gui/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ private static async Task Main(string[] args)
}
Global.InitializeNoWallet();
statusBar = new StatusBarViewModel(Global.Nodes.ConnectedNodes, Global.MemPoolService, Global.IndexDownloader, Global.UpdateChecker);
statusBar = new StatusBarViewModel(Global.Nodes.ConnectedNodes, Global.MemPoolService, Global.Synchronizer, Global.UpdateChecker);
MainWindowViewModel.Instance.StatusBar = statusBar;
if (Global.IndexDownloader.Network != Network.Main)
if (Global.Synchronizer.Network != Network.Main)
{
MainWindowViewModel.Instance.Title += $" - {Global.IndexDownloader.Network}";
MainWindowViewModel.Instance.Title += $" - {Global.Synchronizer.Network}";
}
}).StartShellApp<AppBuilder, MainWindow>("Wasabi Wallet", null, () => MainWindowViewModel.Instance);
}
Expand Down
59 changes: 28 additions & 31 deletions WalletWasabi.Gui/ViewModels/StatusBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using WalletWasabi.Gui.Dialogs;
using System.Runtime.InteropServices;
using System.Reactive.Disposables;
using System.ComponentModel;

namespace WalletWasabi.Gui.ViewModels
{
Expand All @@ -32,7 +33,7 @@ public class StatusBarViewModel : ViewModelBase, IDisposable
{
public NodesCollection Nodes { get; }
public MemPoolService MemPoolService { get; }
public IndexDownloader IndexDownloader { get; }
public WasabiSynchronizer Synchronizer { get; }
public UpdateChecker UpdateChecker { get; }

private UpdateStatus _updateStatus;
Expand Down Expand Up @@ -150,9 +151,8 @@ public string Status

private long _clientOutOfDate;
private long _backendIncompatible;
private CompositeDisposable _disposables;

public StatusBarViewModel(NodesCollection nodes, MemPoolService memPoolService, IndexDownloader indexDownloader, UpdateChecker updateChecker)
public StatusBarViewModel(NodesCollection nodes, MemPoolService memPoolService, WasabiSynchronizer synchronizer, UpdateChecker updateChecker)
{
_clientOutOfDate = 0;
_backendIncompatible = 0;
Expand All @@ -170,21 +170,14 @@ public StatusBarViewModel(NodesCollection nodes, MemPoolService memPoolService,
MemPoolService.TransactionReceived += MemPoolService_TransactionReceived;
Mempool = MemPoolService.TransactionHashes.Count;

IndexDownloader = indexDownloader;
Synchronizer = synchronizer;
UpdateChecker = updateChecker;
IndexDownloader.NewFilter += IndexDownloader_NewFilter;
IndexDownloader.TorStatusChanged += IndexDownloader_TorStatusChanged;
IndexDownloader.BackendStatusChanged += IndexDownloader_BackendStatusChanged;
IndexDownloader.ResponseArrivedIsGenSocksServFail += IndexDownloader_ResponseArrivedIsGenSocksServFail;
Synchronizer.NewFilter += IndexDownloader_NewFilter;
Synchronizer.PropertyChanged += Synchronizer_PropertyChanged;
Synchronizer.ResponseArrivedIsGenSocksServFail += IndexDownloader_ResponseArrivedIsGenSocksServFail;

FiltersLeft = IndexDownloader.GetFiltersLeft();
FiltersLeft = Synchronizer.GetFiltersLeft();

_disposables = new CompositeDisposable {
IndexDownloader.WhenAnyValue(x => x.BestHeight).ObserveOn(RxApp.MainThreadScheduler).Subscribe(_ =>
{
FiltersLeft = IndexDownloader.GetFiltersLeft();
})
};
this.WhenAnyValue(x => x.BlocksLeft).Subscribe(blocks =>
{
SetStatusAndDoUpdateActions();
Expand Down Expand Up @@ -232,6 +225,22 @@ public StatusBarViewModel(NodesCollection nodes, MemPoolService memPoolService,
}, this.WhenAnyValue(x => x.UpdateStatus).Select(x => x != UpdateStatus.Latest));
}

private void Synchronizer_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Synchronizer.TorStatus))
{
Tor = Synchronizer.TorStatus;
}
else if (e.PropertyName == nameof(Synchronizer.BackendStatus))
{
Backend = Synchronizer.BackendStatus;
}
else if (e.PropertyName == nameof(Synchronizer.BestBlockchainHeight))
{
FiltersLeft = Synchronizer.GetFiltersLeft();
}
}

private void IndexDownloader_ResponseArrivedIsGenSocksServFail(object sender, bool isGenSocksServFail)
{
if (isGenSocksServFail)
Expand Down Expand Up @@ -305,19 +314,9 @@ private void SetStatusAndDoUpdateActions()
}
}

private void IndexDownloader_BackendStatusChanged(object sender, BackendStatus e)
{
Backend = e;
}

private void IndexDownloader_TorStatusChanged(object sender, TorStatus e)
{
Tor = e;
}

private void IndexDownloader_NewFilter(object sender, Backend.Models.FilterModel e)
{
FiltersLeft = IndexDownloader.GetFiltersLeft();
FiltersLeft = Synchronizer.GetFiltersLeft();
}

private void MemPoolService_TransactionReceived(object sender, SmartTransaction e)
Expand Down Expand Up @@ -345,14 +344,12 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_disposables.Dispose();
Nodes.Added -= Nodes_Added;
Nodes.Removed -= Nodes_Removed;
MemPoolService.TransactionReceived -= MemPoolService_TransactionReceived;
IndexDownloader.NewFilter -= IndexDownloader_NewFilter;
IndexDownloader.TorStatusChanged -= IndexDownloader_TorStatusChanged;
IndexDownloader.BackendStatusChanged -= IndexDownloader_BackendStatusChanged;
IndexDownloader.ResponseArrivedIsGenSocksServFail -= IndexDownloader_ResponseArrivedIsGenSocksServFail;
Synchronizer.NewFilter -= IndexDownloader_NewFilter;
Synchronizer.PropertyChanged -= Synchronizer_PropertyChanged;
Synchronizer.ResponseArrivedIsGenSocksServFail -= IndexDownloader_ResponseArrivedIsGenSocksServFail;
}

_disposedValue = true;
Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Tests/LiveServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task GetFiltersAsync(NetworkType networkType)
{
using (var client = new WasabiClient(LiveServerTestsFixture.UriMappings[networkType]))
{
var filterModel = IndexDownloader.GetStartingFilter(Network.GetNetwork(networkType.ToString()));
var filterModel = WasabiSynchronizer.GetStartingFilter(Network.GetNetwork(networkType.ToString()));

FiltersResponse filtersResponse = await client.GetFiltersAsync(filterModel.BlockHash, 2);

Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Tests/P2pTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task TestServicesAsync(string networkString)
KeyManager keyManager = KeyManager.CreateNew(out _, "password");
WalletService walletService = new WalletService(
keyManager,
new IndexDownloader(network, Path.Combine(SharedFixture.DataDir, nameof(TestServicesAsync), "IndexDownloader.txt"), new Uri("http://localhost:12345")),
new WasabiSynchronizer(network, Path.Combine(SharedFixture.DataDir, nameof(TestServicesAsync), "IndexDownloader.txt"), new Uri("http://localhost:12345")),
new CcjClient(network, new BlindingRsaKey().PubKey, keyManager, new Uri("http://localhost:12345")),
memPoolService,
nodes,
Expand Down
Loading

0 comments on commit 19962e5

Please sign in to comment.