/// <summary> /// Perform indexing for a given checkpoint type. /// </summary> /// <param name="type">The checkpoint type to index.</param> /// <param name="fromHeight">The height to index from.</param> /// <param name="toHeight">The height to index to.</param> private void PerformIndexing(IndexerCheckpoints type, int fromHeight, int toHeight) { if (!this.nodeLifetime.ApplicationStopping.IsCancellationRequested) { // Index a batch of blocks/transactions/balances/wallets var fetcher = this.GetBlockFetcher(type); if (toHeight > fetcher._LastProcessed.Height) { fetcher.FromHeight = Math.Max(fetcher._LastProcessed.Height + 1, fromHeight); fetcher.ToHeight = toHeight; IIndexTask task = null; switch (type) { case IndexerCheckpoints.Blocks: task = new IndexBlocksTask(this.IndexerConfig, this.loggerFactory); break; case IndexerCheckpoints.Transactions: task = new IndexTransactionsTask(this.IndexerConfig, this.loggerFactory); break; case IndexerCheckpoints.Balances: task = new IndexBalanceTask(this.IndexerConfig, null, this.loggerFactory); break; case IndexerCheckpoints.Wallets: task = new IndexBalanceTask(this.IndexerConfig, this.IndexerConfig.CreateIndexerClient().GetAllWalletRules(), this.loggerFactory); break; } task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(fetcher, this.AzureIndexer.TaskScheduler, this.FullNode.Network); } } }
public int IndexWalletBalances(ChainBase chain) { using (IndexerTrace.NewCorrelation("Import wallet balances to azure started")) { using (var node = this.Configuration.ConnectToNode(false)) { node.VersionHandshake(); var task = new IndexBalanceTask(this.Configuration, this.Configuration.CreateIndexerClient().GetAllWalletRules()); task.SaveProgression = !this.IgnoreCheckpoints; task.Index(this.GetBlockFetcher(this.GetCheckpointInternal(IndexerCheckpoints.Wallets), node, chain), this.TaskScheduler); return(task.IndexedEntities); } } }
public int IndexOrderedBalances(ChainBase chain) { using (IndexerTrace.NewCorrelation("Import balances to azure started")) { using (var node = Configuration.ConnectToNode(false)) { node.VersionHandshake(); var task = new IndexBalanceTask(Configuration, null); task.SaveProgression = !IgnoreCheckpoints; task.Index(GetBlockFetcher(GetCheckpointInternal(IndexerCheckpoints.Balances), node, chain), TaskScheduler); return(task.IndexedEntities); } } }
/// <summary> /// Performs indexing into Azure storage. /// </summary> /// <param name="cancellationToken">The token used for cancellation.</param> /// <returns>A task for asynchronous completion.</returns> private async Task IndexAsync(CancellationToken cancellationToken) { this.logger.LogTrace("()"); while (this.StoreTip.Height < indexerSettings.To && !cancellationToken.IsCancellationRequested) { try { // All indexes will progress more or less in step // Use 'minHeight' to track the current indexed height int minHeight = int.MaxValue; // Index a batch of blocks if (!cancellationToken.IsCancellationRequested) { var task = new IndexBlocksTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Blocks, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Index a batch of transactions if (!cancellationToken.IsCancellationRequested) { var task = new IndexTransactionsTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Transactions, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Index a batch of balances if (!cancellationToken.IsCancellationRequested) { var task = new IndexBalanceTask(this.IndexerConfig, null); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Balances, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Index a batch of wallets if (!cancellationToken.IsCancellationRequested) { var task = new IndexBalanceTask(this.IndexerConfig, this.IndexerConfig.CreateIndexerClient().GetAllWalletRules()); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; var fetcher = this.GetBlockFetcher(IndexerCheckpoints.Wallets, cancellationToken); task.Index(fetcher, this.AzureIndexer.TaskScheduler); minHeight = Math.Min(minHeight, fetcher._LastProcessed.Height); } // Update the StoreTip value from the minHeight this.SetStoreTip(this.Chain.GetBlock(Math.Min(minHeight, this.indexerSettings.To))); } catch (OperationCanceledException) { break; } catch (Exception ex) { // If something goes wrong then try again 1 minute later IndexerTrace.ErrorWhileImportingBlockToAzure(this.StoreTip.HashBlock, ex); await Task.Delay(TimeSpan.FromMinutes(1), cancellationToken).ContinueWith(t => { }).ConfigureAwait(false); } } this.logger.LogTrace("(-)"); }
/// <summary> /// Performs indexing into Azure storage. /// </summary> /// <param name="cancellationToken">The token used for cancellation.</param> /// <returns>A task for asynchronous completion.</returns> private async Task IndexAsync(CancellationToken cancellationToken) { this.logger.LogTrace("()"); while (this.StoreTip.Height < indexerSettings.To && !cancellationToken.IsCancellationRequested) { try { // All indexes will progress more or less in step int fromHeight = this.StoreTip.Height + 1; int toHeight = Math.Min(this.StoreTip.Height + IndexBatchSize, this.indexerSettings.To); // Index a batch of blocks if (!cancellationToken.IsCancellationRequested && toHeight > this.BlocksFetcher._LastProcessed.Height) { this.BlocksFetcher.FromHeight = Math.Max(this.BlocksFetcher._LastProcessed.Height + 1, fromHeight); this.BlocksFetcher.ToHeight = toHeight; var task = new IndexBlocksTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.BlocksFetcher, this.AzureIndexer.TaskScheduler); } // Index a batch of transactions if (!cancellationToken.IsCancellationRequested && toHeight > this.TransactionsFetcher._LastProcessed.Height) { this.TransactionsFetcher.FromHeight = Math.Max(this.TransactionsFetcher._LastProcessed.Height + 1, fromHeight); this.TransactionsFetcher.ToHeight = toHeight; var task = new IndexTransactionsTask(this.IndexerConfig); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.TransactionsFetcher, this.AzureIndexer.TaskScheduler); } // Index a batch of balances if (!cancellationToken.IsCancellationRequested && toHeight > this.BalancesFetcher._LastProcessed.Height) { this.BalancesFetcher.FromHeight = Math.Max(this.BalancesFetcher._LastProcessed.Height + 1, fromHeight); this.BalancesFetcher.ToHeight = toHeight; var task = new IndexBalanceTask(this.IndexerConfig, null); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.BalancesFetcher, this.AzureIndexer.TaskScheduler); } // Index a batch of wallets if (!cancellationToken.IsCancellationRequested && toHeight > this.WalletsFetcher._LastProcessed.Height) { this.WalletsFetcher.FromHeight = Math.Max(this.WalletsFetcher._LastProcessed.Height + 1, fromHeight); this.WalletsFetcher.ToHeight = toHeight; var task = new IndexBalanceTask(this.IndexerConfig, this.IndexerConfig.CreateIndexerClient().GetAllWalletRules()); task.SaveProgression = !this.indexerSettings.IgnoreCheckpoints; task.Index(this.WalletsFetcher, this.AzureIndexer.TaskScheduler); } // Update the StoreTip value from the minHeight int minHeight = this.BlocksFetcher._LastProcessed.Height; minHeight = Math.Min(minHeight, this.BalancesFetcher._LastProcessed.Height); minHeight = Math.Min(minHeight, this.TransactionsFetcher._LastProcessed.Height); minHeight = Math.Min(minHeight, this.WalletsFetcher._LastProcessed.Height); this.SetStoreTip(this.Chain.GetBlock(minHeight)); } catch (OperationCanceledException) { break; } catch (Exception ex) { // If something goes wrong then try again 1 minute later this.logger.LogError(ex.Message); IndexerTrace.ErrorWhileImportingBlockToAzure(this.StoreTip.HashBlock, ex); await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken).ContinueWith(t => { }).ConfigureAwait(false); } } this.logger.LogTrace("(-)"); }
public int IndexWalletBalances(ChainBase chain) { using(IndexerTrace.NewCorrelation("Import wallet balances to azure started").Open()) { using(var node = Configuration.ConnectToNode(false)) { node.VersionHandshake(); var task = new IndexBalanceTask(Configuration, Configuration.CreateIndexerClient().GetAllWalletRules()); task.SaveProgression = !IgnoreCheckpoints; task.Index(GetBlockFetcher(GetCheckpointInternal(IndexerCheckpoints.Wallets), node, chain), TaskScheduler); return task.IndexedEntities; } } }