public async Task FlushAsync() { // before flushing the coinview persist the stake store // the stake store depends on the last block hash // to be stored after the stake store is persisted if (this.stakeChainStore != null) { await this.stakeChainStore.Flush(true); } if (innerBlockHash == null) { innerBlockHash = await inner.GetBlockHashAsync().ConfigureAwait(false); } using (this.lockobj.LockWrite()) { WaitOngoingTasks(); if (innerBlockHash == null) { return; } var unspent = unspents.Where(u => u.Value.IsDirty) .ToArray(); var originalOutputs = unspent.Select(u => u.Value.OriginalOutputs).ToList(); foreach (var u in unspent) { u.Value.IsDirty = false; u.Value.ExistInInner = true; u.Value.OriginalOutputs = u.Value.UnspentOutputs?._Outputs.ToArray(); } this.flushing = Inner.SaveChangesAsync(unspent.Select(u => u.Value.UnspentOutputs).ToArray(), originalOutputs, innerBlockHash, blockHash); //Remove from cache prunable entries as they are being flushed down foreach (var c in unspent.Where(c => c.Value.UnspentOutputs != null && c.Value.UnspentOutputs.IsPrunable)) { unspents.Remove(c.Key); } innerBlockHash = blockHash; } //Can't await inside a lock await this.flushing.ConfigureAwait(false); }
public async Task FlushAsync() { if (_InnerBlockHash == null) { _InnerBlockHash = await _Inner.GetBlockHashAsync().ConfigureAwait(false); } KeyValuePair <uint256, CacheItem>[] unspent = null; using (_Lock.LockWrite()) { WaitOngoingTasks(); if (_InnerBlockHash == null) { return; } unspent = _Unspents.Where(u => u.Value.IsDirty) .ToArray(); var originalOutputs = unspent.Select(u => u.Value.OriginalOutputs).ToList(); foreach (var u in unspent) { u.Value.IsDirty = false; u.Value.ExistInInner = true; u.Value.OriginalOutputs = u.Value.UnspentOutputs?._Outputs.ToArray(); } _Flushing = Inner.SaveChangesAsync(unspent.Select(u => u.Value.UnspentOutputs).ToArray(), originalOutputs, _InnerBlockHash, _BlockHash); //Remove from cache prunable entries as they are being flushed down foreach (var c in unspent.Where(c => c.Value.UnspentOutputs != null && c.Value.UnspentOutputs.IsPrunable)) { _Unspents.Remove(c.Key); } _InnerBlockHash = _BlockHash; } //Can't await inside a lock await _Flushing.ConfigureAwait(false); }
public void Initialize() { var utxoHash = _utxoSet.GetBlockHashAsync().GetAwaiter().GetResult(); while (true) { _Tip = Chain.GetBlock(utxoHash); if (_Tip != null) { break; } utxoHash = _utxoSet.Rewind().GetAwaiter().GetResult(); } Puller.SetLocation(Tip); bip9 = new ThresholdConditionCache(_Validator.ConsensusParams); }
public void Log() { StringBuilder benchLogs = new StringBuilder(); if (lookaheadPuller != null) { benchLogs.AppendLine("======Block Puller======"); benchLogs.AppendLine("Lookahead:".PadRight(Logs.ColumnLength) + lookaheadPuller.ActualLookahead + " blocks"); benchLogs.AppendLine("Downloaded:".PadRight(Logs.ColumnLength) + lookaheadPuller.MedianDownloadCount + " blocks"); benchLogs.AppendLine("=========================="); } benchLogs.AppendLine("Persistent Tip:".PadRight(Logs.ColumnLength) + this.chain.GetBlock(bottom.GetBlockHashAsync().Result).Height); if (cache != null) { benchLogs.AppendLine("Cache Tip".PadRight(Logs.ColumnLength) + this.chain.GetBlock(cache.GetBlockHashAsync().Result).Height); benchLogs.AppendLine("Cache entries".PadRight(Logs.ColumnLength) + cache.CacheEntryCount); } var snapshot = this.consensusLoop.Validator.PerformanceCounter.Snapshot(); benchLogs.AppendLine((snapshot - lastSnapshot).ToString()); lastSnapshot = snapshot; if (dbreeze != null) { var snapshot2 = dbreeze.PerformanceCounter.Snapshot(); benchLogs.AppendLine((snapshot2 - lastSnapshot2).ToString()); lastSnapshot2 = snapshot2; } if (cache != null) { var snapshot3 = cache.PerformanceCounter.Snapshot(); benchLogs.AppendLine((snapshot3 - lastSnapshot3).ToString()); lastSnapshot3 = snapshot3; } benchLogs.AppendLine(this.connectionManager.GetStats()); Logs.Bench.LogInformation(benchLogs.ToString()); }