Пример #1
0
        private async Task AddBlockAsync(BlockDto blockDto)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var block = await _blockInsert.InsertBlockAsync(blockDto);

            if (block == null)
            {
                throw new NullReferenceException("Something failed inserting the new block");
            }

            stopwatch.Stop();
            Logger.LogInformation($"Block {block.Height} synced in {stopwatch.Elapsed:g}");
        }
Пример #2
0
        private async Task ScanAndRepair(int blockHeight)
        {
            var dbBlock = await _blockQuery.GetBlockAsync(blockHeight, true);

            var nxsBlock = await _nexusQuery.GetBlockAsync(blockHeight, true);

            if (nxsBlock == null)
            {
                var retryCounter = 0;

                while (retryCounter < 3)
                {
                    nxsBlock = await _nexusQuery.GetBlockAsync(blockHeight, true);

                    if (nxsBlock != null)
                    {
                        break;
                    }

                    await Task.Delay(1000);

                    retryCounter++;
                }

                if (nxsBlock == null)
                {
                    Logger.LogWarning($"Nexus block {blockHeight} is returning null");
                    return;
                }
            }

            var nullDbBlock = dbBlock == null;

            if (nullDbBlock || dbBlock.Hash != nxsBlock.Hash)
            {
                BlockDto deleteBlock;

                if (nullDbBlock)
                {
                    deleteBlock = new BlockDto {
                        Height = blockHeight
                    };

                    Logger.LogWarning($"Block {blockHeight} is returning null from the database");
                }
                else
                {
                    deleteBlock = dbBlock;

                    Logger.LogWarning($"Block {blockHeight} has a mismatched hash");
                    Logger.LogWarning($"Reverting address aggregation from block {blockHeight} addresses");

                    await _addressAggregator.RevertAggregate(deleteBlock);
                }

                Logger.LogWarning($"Deleting block, transaction and io data for block {blockHeight}");
                await _blockDelete.DeleteBlockAsync(deleteBlock);

                Logger.LogWarning($"Inserting new data for block {blockHeight}");
                await _blockInsert.InsertBlockAsync(nxsBlock);

                await _addressAggregator.AggregateAddressesAsync(nxsBlock);
            }
        }