/// <inheritdoc /> public override async Task <bool> OnExecute() { if (Runner.GlobalState.ReorgMode == true) { // null the store tip so the document count will be taken form disk Runner.GlobalState.StoreTip = null; // rewind the data in store Runner.GlobalState.StoreTip = await syncOperations.RewindToBestChain(syncConnection); Runner.GlobalState.PullingTip = null; Queue.Clear(); Runner.GlobalState.ReorgMode = false; return(false); } if (Runner.GlobalState.IndexMode) { return(false); } if (!TryDequeue(out StorageBatch batch)) { return(await Task.FromResult(false)); } ValidateBatch(batch); watch.Restart(); Runner.GlobalState.StoreTip = storageOperations.PushStorageBatch(batch); watch.Stop(); if (Runner.GlobalState.StoreTip == null) { throw new ApplicationException("Store tip was not persisted"); } long totalBlocks = batch.BlockTable.Count; // insertStats.Sum((tuple => tuple.count)); double totalSeconds = watch.Elapsed.TotalSeconds; // insertStats.Sum((tuple => tuple.seconds)); double blocksPerSecond = totalBlocks / totalSeconds; double secondsPerBlock = totalSeconds / totalBlocks; log.LogInformation($"Store - blocks={batch.BlockTable.Count}, outputs={batch.OutputTable.Count}, inputs={batch.InputTable.Count}, trx={batch.TransactionBlockTable.Count}, total Size = {((decimal)batch.TotalSize / 1000000):0.00}mb, tip={Runner.GlobalState.StoreTip.BlockIndex}, Seconds = {watch.Elapsed.TotalSeconds}, inserts = {blocksPerSecond:0.00}b/s ({secondsPerBlock:0.00}s/b)"); foreach (BlockTable mapBlocksValue in batch.BlockTable.Values) { syncConnection.RecentItems.Add((DateTime.UtcNow, TimeSpan.FromSeconds(blocksPerSecond), mapBlocksValue.BlockSize)); } var notifications = new AddressNotifications { Addresses = new List <string>() }; // count.Items.Where(ad => ad.Addresses != null).SelectMany(s => s.Addresses).Distinct().ToList() }; Runner.Get <Notifier>().Enqueue(notifications); return(await Task.FromResult(true)); }
/// <inheritdoc /> public override async Task <bool> OnExecute() { SyncBlockTransactionsOperation item; if (this.TryDequeue(out item)) { var stoper = Stopwatch.Start(); this.storageOperations.ValidateBlock(item); var count = this.storageOperations.InsertTransactions(item); if (item.BlockInfo != null) { BlockInfo blockInfo; if (!this.Runner.SyncingBlocks.CurrentSyncing.TryRemove(item.BlockInfo.Hash, out blockInfo)) { throw new Exception(string.Format("Failed to remove block hash {0} from collection", item.BlockInfo.Hash)); } this.syncConnection.RecentItems.Add((DateTime.UtcNow, stoper.Elapsed, item.BlockInfo.Size)); } var notifications = new AddressNotifications { Addresses = count.Items.Where(ad => ad.Addresses != null).SelectMany(s => s.Addresses).Distinct().ToList() }; this.Runner.Get <Notifier>().Enqueue(notifications); stoper.Stop(); var message = item.BlockInfo != null? string.Format("Seconds = {0} - BlockIndex = {1} - TotalItems = {2} - Size = {3} kb", stoper.Elapsed.TotalSeconds, item.BlockInfo.Height, count.Transactions + count.InputsOutputs, item.BlockInfo.Size) : string.Format("Seconds = {0} - PoolSync - TotalItems = {1}", stoper.Elapsed.TotalSeconds, count.Transactions + count.InputsOutputs); this.log.LogDebug(message); return(await Task.FromResult(true)); } return(await Task.FromResult(false)); }
/// <inheritdoc /> public override async Task <bool> OnExecute() { SyncBlockTransactionsOperation item; if (this.TryDequeue(out item)) { var stoper = Stopwatch.Start(); this.storageOperations.ValidateBlock(item); var count = this.storageOperations.InsertTransactions(item); if (item.BlockInfo != null) { BlockInfo blockInfo; if (!this.Runner.SyncingBlocks.CurrentSyncing.TryRemove(item.BlockInfo.Hash, out blockInfo)) { throw new ApplicationException(string.Format("Failed to remove block hash {0} from collection", item.BlockInfo.Hash)); } } var notifications = new AddressNotifications { Addresses = count.Items.SelectMany(s => s.Addresses).Distinct().ToList() }; this.Runner.Get <Notifier>().Enqueue(notifications); stoper.Stop(); var message = item.BlockInfo != null? string.Format("Seconds = {0} - BlockIndex = {1} - TotalItems = {2}", stoper.Elapsed.TotalSeconds, item.BlockInfo.Height, count.Transactions + count.Inputs + count.Outputs) : string.Format("Seconds = {0} - PoolSync - TotalItems = {1}", stoper.Elapsed.TotalSeconds, count.Transactions + count.Inputs + count.Outputs); this.tracer.Trace("BlockStore ", message, ConsoleColor.White); return(await Task.FromResult(true)); } return(await Task.FromResult(false)); }