Ejemplo n.º 1
0
        /// <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);
                }
            }
        }
Ejemplo n.º 2
0
        public Task IndexAsync(params Block[] blocks)
        {
            this.logger.LogTrace("()");

            var  task      = new IndexBlocksTask(this.Configuration, this.loggerFactory);
            Task indexTask = task.IndexAsync(blocks, this.TaskScheduler);

            this.logger.LogTrace("()");
            return(indexTask);
        }
Ejemplo n.º 3
0
        public void Index(params Block[] blocks)
        {
            this.logger.LogTrace("()");

            var task = new IndexBlocksTask(this.Configuration, this.loggerFactory);

            task.Index(blocks, this.TaskScheduler);

            this.logger.LogTrace("(-)");
        }
Ejemplo n.º 4
0
 public long IndexBlocks(ChainBase chain = null)
 {
     using (IndexerTrace.NewCorrelation("Import blocks to azure started"))
     {
         using (var node = this.Configuration.ConnectToNode(false))
         {
             node.VersionHandshake();
             var task = new IndexBlocksTask(this.Configuration);
             task.SaveProgression = !this.IgnoreCheckpoints;
             task.Index(this.GetBlockFetcher(this.GetCheckpointInternal(IndexerCheckpoints.Blocks), node, chain), this.TaskScheduler);
             return(task.IndexedBlocks);
         }
     }
 }
Ejemplo n.º 5
0
        public Task IndexAsync(params Block[] blocks)
        {
            var task = new IndexBlocksTask(this.Configuration);

            return(task.IndexAsync(blocks, this.TaskScheduler));
        }
Ejemplo n.º 6
0
        public void Index(params Block[] blocks)
        {
            var task = new IndexBlocksTask(this.Configuration);

            task.Index(blocks, this.TaskScheduler);
        }
Ejemplo n.º 7
0
        /// <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("(-)");
        }
Ejemplo n.º 8
0
        /// <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("(-)");
        }
Ejemplo n.º 9
0
 public long IndexBlocks(ChainBase chain = null)
 {
     using(IndexerTrace.NewCorrelation("Import blocks to azure started").Open())
     {
         using(var node = Configuration.ConnectToNode(false))
         {
             node.VersionHandshake();
             var task = new IndexBlocksTask(Configuration);
             task.SaveProgression = !IgnoreCheckpoints;
             task.Index(GetBlockFetcher(GetCheckpointInternal(IndexerCheckpoints.Blocks), node, chain), TaskScheduler);
             return task.IndexedBlocks;
         }
     }
 }
Ejemplo n.º 10
0
 public Task IndexAsync(params Block[] blocks)
 {
     var task = new IndexBlocksTask(Configuration);
     return task.IndexAsync(blocks, TaskScheduler);
 }
Ejemplo n.º 11
0
 public void Index(params Block[] blocks)
 {
     var task = new IndexBlocksTask(Configuration);
     task.Index(blocks, TaskScheduler);
 }