public async Task InitializeAsync(CancellationToken cancel) { try { InitializingChanged?.Invoke(null, true); if (!Synchronizer.IsRunning) { throw new NotSupportedException($"{nameof(Synchronizer)} is not running."); } while (!BitcoinStore.IsInitialized) { await Task.Delay(100).ConfigureAwait(false); cancel.ThrowIfCancellationRequested(); } await RuntimeParams.LoadAsync(); using (await HandleFiltersLock.LockAsync()) { await LoadWalletStateAsync(cancel); await LoadDummyMempoolAsync(); } } finally { InitializingChanged?.Invoke(null, false); } }
private async void IndexDownloader_NewFilterAsync(object sender, FilterModel filterModel) { try { using (await HandleFiltersLock.LockAsync()) { if (KeyManager.GetBestHeight() < filterModel.Header.Height) { await ProcessFilterModelAsync(filterModel, CancellationToken.None); } } NewFilterProcessed?.Invoke(this, filterModel); do { await Task.Delay(100); if (Synchronizer is null || BitcoinStore?.SmartHeaderChain is null) { return; } // Make sure fully synced and this filter is the lastest filter. if (BitcoinStore.SmartHeaderChain.HashesLeft != 0 || BitcoinStore.SmartHeaderChain.TipHash != filterModel.Header.BlockHash) { return; } } while (Synchronizer.AreRequestsBlocked()); // If requests are blocked, delay mempool cleanup, because coinjoin answers are always priority. await BitcoinStore.MempoolService?.TryPerformMempoolCleanupAsync(Synchronizer?.WasabiClient?.TorClient?.DestinationUriAction, Synchronizer?.WasabiClient?.TorClient?.TorSocks5EndPoint); } catch (Exception ex) { Logger.LogWarning(ex); } }
private async void IndexDownloader_NewFilterAsync(object sender, FilterModel filterModel) { using (HandleFiltersLock.Lock()) using (WalletBlocksLock.Lock()) { if (filterModel.Filter != null && !WalletBlocks.ContainsValue(filterModel.BlockHash)) { await ProcessFilterModelAsync(filterModel, CancellationToken.None); } } NewFilterProcessed?.Invoke(this, filterModel); }
public async Task InitializeAsync(CancellationToken cancel) { if (!IndexDownloader.IsRunning) { throw new NotSupportedException($"{nameof(IndexDownloader)} is not running."); } using (HandleFiltersLock.Lock()) using (WalletBlocksLock.Lock()) { // Go through the filters and que to download the matches. var filters = IndexDownloader.GetFiltersIncluding(IndexDownloader.StartingFilter.BlockHeight); foreach (var filterModel in filters.Where(x => x.Filter != null && !WalletBlocks.ContainsValue(x.BlockHash))) // Filter can be null if there is no bech32 tx. { await ProcessFilterModelAsync(filterModel, cancel); } } }
private async void IndexDownloader_ReorgedAsync(object sender, uint256 invalidBlockHash) { using (HandleFiltersLock.Lock()) using (WalletBlocksLock.Lock()) { var elem = WalletBlocks.SingleOrDefault(x => x.Value == invalidBlockHash); await DeleteBlockAsync(invalidBlockHash); WalletBlocks.RemoveByValue(invalidBlockHash); ProcessedBlocks.Remove(invalidBlockHash); if (elem.Key != null) { foreach (var toRemove in Coins.Where(x => x.Height == elem.Key).ToHashSet()) { RemoveCoinRecursively(toRemove); } } } }
private async void IndexDownloader_ReorgedAsync(object sender, FilterModel invalidFilter) { try { using (await HandleFiltersLock.LockAsync()) { uint256 invalidBlockHash = invalidFilter.Header.BlockHash; await DeleteBlockAsync(invalidBlockHash); KeyManager.SetMaxBestHeight(new Height(invalidFilter.Header.Height - 1)); TransactionProcessor.UndoBlock((int)invalidFilter.Header.Height); BitcoinStore.TransactionStore.ReleaseToMempoolFromBlock(invalidBlockHash); } } catch (Exception ex) { Logger.LogWarning(ex); } }