private async Task AggregateAddressesAsync(BlockDto blockDto) { var stopwatch = new Stopwatch(); Logger.LogInformation($"Syncing address from block {blockDto.Height}..."); stopwatch.Start(); await _addressAggregator.AggregateAddressesAsync(blockDto); stopwatch.Stop(); Logger.LogInformation($"Address synced in {stopwatch.Elapsed:g}"); }
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); } }