Skip to content

Commit

Permalink
Console Cleanup (#408)
Browse files Browse the repository at this point in the history
* Suppress bench logs

* Done

* Update NodeStats.cs

* Fix Test
  • Loading branch information
fassadlr authored Feb 9, 2021
1 parent 55327ba commit c48a780
Show file tree
Hide file tree
Showing 45 changed files with 230 additions and 197 deletions.
7 changes: 1 addition & 6 deletions src/Stratis.Bitcoin.Features.BlockStore/BlockStoreFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ private void AddInlineStats(StringBuilder log)
ChainedHeader highestBlock = this.chainState.BlockStoreTip;

if (highestBlock != null)
{
var builder = new StringBuilder();
builder.Append("BlockStore.Height: ".PadRight(LoggingConfiguration.ColumnLength + 1) + highestBlock.Height.ToString().PadRight(8));
builder.Append(" BlockStore.Hash: ".PadRight(LoggingConfiguration.ColumnLength - 1) + highestBlock.HashBlock);
log.AppendLine(builder.ToString());
}
log.AppendLine("BlockStore Height".PadRight(LoggingConfiguration.ColumnLength) + $": {highestBlock.Height}".PadRight(10) + $"(Hash: {highestBlock.HashBlock})");
}

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions src/Stratis.Bitcoin.Features.BlockStore/BlockStoreQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NBitcoin;
using Stratis.Bitcoin.AsyncWork;
using Stratis.Bitcoin.Base;
using Stratis.Bitcoin.Configuration.Logging;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Primitives;
Expand Down Expand Up @@ -456,10 +457,10 @@ private void AddComponentStats(StringBuilder log)
{
if (this.storeTip != null)
{
log.AppendLine(">> Block Store");
log.AppendLine("Batch Size".PadRight(LoggingConfiguration.ColumnLength, ' ') + $": {this.currentBatchSizeBytes.BytesToMegaBytes()} MB / {this.BatchThresholdSizeBytes.BytesToMegaBytes()} MB ({this.batch.Count} batched)");
log.AppendLine("Queue Size".PadRight(LoggingConfiguration.ColumnLength, ' ') + $": {this.blocksQueueSizeBytes.BytesToMegaBytes()} MB ({this.blocksQueue.Count} queued)");
log.AppendLine();
log.AppendLine("======BlockStore======");
log.AppendLine($"Batch Size: {this.currentBatchSizeBytes.BytesToMegaBytes()} MB / {this.BatchThresholdSizeBytes.BytesToMegaBytes()} MB ({this.batch.Count} batched blocks)");
log.AppendLine($"Queue Size: {this.blocksQueueSizeBytes.BytesToMegaBytes()} MB ({this.blocksQueue.Count} queued blocks)");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Moq;
using NBitcoin;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Configuration.Logging;
using Stratis.Bitcoin.Configuration.Settings;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Features.Consensus.CoinViews;
using Stratis.Bitcoin.Features.Consensus.ProvenBlockHeaders;
using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Networks;
using Stratis.Bitcoin.Tests.Common;
using Stratis.Bitcoin.Utilities;
Expand Down Expand Up @@ -38,7 +40,7 @@ public CoinviewTests()
this.dataFolder = TestBase.CreateDataFolder(this);
this.dateTimeProvider = new DateTimeProvider();
this.loggerFactory = new ExtendedLoggerFactory();
this.nodeStats = new NodeStats(this.dateTimeProvider, this.loggerFactory);
this.nodeStats = new NodeStats(this.dateTimeProvider, NodeSettings.Default(this.network), new Mock<IVersionProvider>().Object);

this.coindb = new DBreezeCoindb(this.network, this.dataFolder, this.dateTimeProvider, this.loggerFactory, this.nodeStats, new DBreezeSerializer(this.network.Consensus.ConsensusFactory));
this.coindb.Initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using FluentAssertions;
using Moq;
using NBitcoin;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Features.Consensus.ProvenBlockHeaders;
using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Networks;
Expand All @@ -29,7 +30,7 @@ private SortedDictionary<int, ProvenBlockHeader> PendingBatch

public ProvenBlockHeaderStoreTests() : base(new StraxTest())
{
var nodeStats = new NodeStats(DateTimeProvider.Default, this.LoggerFactory.Object);
var nodeStats = new NodeStats(DateTimeProvider.Default, NodeSettings.Default(this.Network), new Mock<IVersionProvider>().Object);

var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);

Expand Down Expand Up @@ -445,7 +446,7 @@ private ProvenBlockHeaderStore SetupStore()
var ibdMock = new Mock<IInitialBlockDownloadState>();
ibdMock.Setup(s => s.IsInitialBlockDownload()).Returns(false);

return new ProvenBlockHeaderStore(DateTimeProvider.Default, this.LoggerFactory.Object, this.provenBlockHeaderRepository, new NodeStats(DateTimeProvider.Default, this.LoggerFactory.Object), ibdMock.Object);
return new ProvenBlockHeaderStore(DateTimeProvider.Default, this.LoggerFactory.Object, this.provenBlockHeaderRepository, new NodeStats(DateTimeProvider.Default, NodeSettings.Default(Network), new Mock<IVersionProvider>().Object), ibdMock.Object);
}

private static void WaitLoop(Func<bool> act, string failureReason = "Unknown Reason", int retryDelayInMiliseconds = 1000, CancellationToken cancellationToken = default(CancellationToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Stratis.Bitcoin.Features.Consensus.CoinViews;
using Stratis.Bitcoin.Features.Consensus.Rules;
using Stratis.Bitcoin.Features.Consensus.Rules.CommonRules;
using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Signals;
using Stratis.Bitcoin.Tests.Common;
using Stratis.Bitcoin.Utilities;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected void WhenExecutingTheRule(ConsensusRuleBase rule, RuleContext ruleCont
new NodeDeployments(KnownNetworks.RegTest, new ChainIndexer(this.network)),
new ConsensusSettings(NodeSettings.Default(KnownNetworks.RegTest)), new Mock<ICheckpoints>().Object, new Mock<ICoinView>().Object, new Mock<IChainState>().Object,
new InvalidBlockHashStore(dateTimeProvider),
new NodeStats(dateTimeProvider, loggerFactory),
new NodeStats(dateTimeProvider, NodeSettings.Default(this.network), new Mock<IVersionProvider>().Object),
new AsyncProvider(loggerFactory, new Mock<ISignals>().Object),
new ConsensusRulesContainer());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Stratis.Bitcoin.Features.Consensus.CoinViews;
using Stratis.Bitcoin.Features.Consensus.Interfaces;
using Stratis.Bitcoin.Features.Consensus.ProvenBlockHeaders;
using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Signals;
using Stratis.Bitcoin.Tests.Common;
using Stratis.Bitcoin.Utilities;
Expand Down Expand Up @@ -108,7 +109,7 @@ public PosConsensusRuleUnitTestBase() : base(KnownNetworks.StraxTest)
Logger = this.logger.Object,
Parent = new TestPosConsensusRules(this.network, this.loggerFactory.Object, this.dateTimeProvider.Object, this.ChainIndexer, this.nodeDeployments,
this.consensusSettings, this.checkpoints.Object, this.coinView.Object, this.stakeChain.Object, this.stakeValidator.Object, this.chainState.Object,
new InvalidBlockHashStore(new DateTimeProvider()), new NodeStats(this.dateTimeProvider.Object, this.loggerFactory.Object), this.rewindDataIndexStore.Object, this.asyncProvider, new ConsensusRulesContainer())
new InvalidBlockHashStore(new DateTimeProvider()), new NodeStats(this.dateTimeProvider.Object, NodeSettings.Default(this.network), new Mock<IVersionProvider>().Object), this.rewindDataIndexStore.Object, this.asyncProvider, new ConsensusRulesContainer())
};
}
}
Expand Down Expand Up @@ -205,7 +206,7 @@ public TestConsensusRulesUnitTestBase() : base(KnownNetworks.TestNet)
public override TestConsensusRules InitializeConsensusRules()
{
return new TestConsensusRules(this.network, this.loggerFactory.Object, this.dateTimeProvider.Object, this.ChainIndexer, this.nodeDeployments,
this.consensusSettings, this.checkpoints.Object, this.chainState.Object, new InvalidBlockHashStore(this.dateTimeProvider.Object), new NodeStats(this.dateTimeProvider.Object, this.loggerFactory.Object), new ConsensusRulesContainer());
this.consensusSettings, this.checkpoints.Object, this.chainState.Object, new InvalidBlockHashStore(this.dateTimeProvider.Object), new NodeStats(this.dateTimeProvider.Object, NodeSettings.Default(this.network), new Mock<IVersionProvider>().Object), new ConsensusRulesContainer());
}
}

Expand Down Expand Up @@ -238,7 +239,7 @@ public override TestPosConsensusRules InitializeConsensusRules()
{
return new TestPosConsensusRules(this.network, this.loggerFactory.Object, this.dateTimeProvider.Object, this.ChainIndexer,
this.nodeDeployments, this.consensusSettings, this.checkpoints.Object, this.coinView.Object, this.stakeChain.Object,
this.stakeValidator.Object, this.chainState.Object, new InvalidBlockHashStore(this.dateTimeProvider.Object), new NodeStats(this.dateTimeProvider.Object, this.loggerFactory.Object), this.rewindDataIndexStore.Object, this.asyncProvider, new ConsensusRulesContainer());
this.stakeValidator.Object, this.chainState.Object, new InvalidBlockHashStore(this.dateTimeProvider.Object), new NodeStats(this.dateTimeProvider.Object, NodeSettings.Default(this.network), new Mock<IVersionProvider>().Object), this.rewindDataIndexStore.Object, this.asyncProvider, new ConsensusRulesContainer());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Moq;
using NBitcoin;
using NBitcoin.Rules;
using Stratis.Bitcoin.AsyncWork;
using Stratis.Bitcoin.Base;
using Stratis.Bitcoin.Base.Deployments;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Configuration.Logging;
using Stratis.Bitcoin.Configuration.Settings;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Consensus.Rules;
using Stratis.Bitcoin.Features.Consensus.CoinViews;
using Stratis.Bitcoin.Features.Consensus.Interfaces;
using Stratis.Bitcoin.Features.Consensus.ProvenBlockHeaders;
using Stratis.Bitcoin.Features.Consensus.Rules;
using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Signals;
using Stratis.Bitcoin.Utilities;
using Xunit.Sdk;
Expand Down Expand Up @@ -156,7 +157,7 @@ internal static class TestRulesContextFactory
/// <summary>
/// Creates test chain with a consensus loop.
/// </summary>
public static TestRulesContext CreateAsync(Network network, [CallerMemberName]string pathName = null)
public static TestRulesContext CreateAsync(Network network, [CallerMemberName] string pathName = null)
{
var testRulesContext = new TestRulesContext() { Network = network };

Expand All @@ -178,7 +179,7 @@ public static TestRulesContext CreateAsync(Network network, [CallerMemberName]st
var deployments = new NodeDeployments(testRulesContext.Network, testRulesContext.ChainIndexer);
testRulesContext.ConsensusRuleEngine = new PowConsensusRuleEngine(testRulesContext.Network, testRulesContext.LoggerFactory, testRulesContext.DateTimeProvider,
testRulesContext.ChainIndexer, deployments, consensusSettings, testRulesContext.Checkpoints, new InMemoryCoinView(new HashHeightPair()), testRulesContext.ChainState,
new InvalidBlockHashStore(DateTimeProvider.Default), new NodeStats(DateTimeProvider.Default, testRulesContext.LoggerFactory), testRulesContext.AsyncProvider, new ConsensusRulesContainer()).SetupRulesEngineParent();
new InvalidBlockHashStore(DateTimeProvider.Default), new NodeStats(testRulesContext.DateTimeProvider, testRulesContext.NodeSettings, new Mock<IVersionProvider>().Object), testRulesContext.AsyncProvider, new ConsensusRulesContainer()).SetupRulesEngineParent();

return testRulesContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static async Task<TestChainContext> CreateAsync(Network network, string d
testChainContext.InitialBlockDownloadState = new InitialBlockDownloadState(testChainContext.ChainState, testChainContext.Network, consensusSettings, new Checkpoints(), testChainContext.NodeSettings.LoggerFactory, testChainContext.DateTimeProvider);

var inMemoryCoinView = new InMemoryCoinView(new HashHeightPair(testChainContext.ChainIndexer.Tip));
var cachedCoinView = new CachedCoinView(network, new Checkpoints(), inMemoryCoinView, DateTimeProvider.Default, testChainContext.LoggerFactory, new NodeStats(testChainContext.DateTimeProvider, testChainContext.LoggerFactory), new ConsensusSettings(testChainContext.NodeSettings));
var cachedCoinView = new CachedCoinView(network, new Checkpoints(), inMemoryCoinView, DateTimeProvider.Default, testChainContext.LoggerFactory, new NodeStats(testChainContext.DateTimeProvider, testChainContext.NodeSettings, new Mock<IVersionProvider>().Object), new ConsensusSettings(testChainContext.NodeSettings));

var dataFolder = new DataFolder(TestBase.AssureEmptyDir(dataDir).FullName);
testChainContext.PeerAddressManager =
Expand All @@ -139,7 +139,7 @@ public static async Task<TestChainContext> CreateAsync(Network network, string d
var deployments = new NodeDeployments(testChainContext.Network, testChainContext.ChainIndexer);
testChainContext.ConsensusRules = new PowConsensusRuleEngine(testChainContext.Network, testChainContext.LoggerFactory, testChainContext.DateTimeProvider,
testChainContext.ChainIndexer, deployments, consensusSettings, testChainContext.Checkpoints, cachedCoinView, testChainContext.ChainState,
new InvalidBlockHashStore(dateTimeProvider), new NodeStats(dateTimeProvider, testChainContext.LoggerFactory), testChainContext.AsyncProvider, new ConsensusRulesContainer()).SetupRulesEngineParent();
new InvalidBlockHashStore(dateTimeProvider), new NodeStats(dateTimeProvider, testChainContext.NodeSettings, new Mock<IVersionProvider>().Object), testChainContext.AsyncProvider, new ConsensusRulesContainer()).SetupRulesEngineParent();

testChainContext.HeaderValidator = new HeaderValidator(testChainContext.ConsensusRules, testChainContext.LoggerFactory);
testChainContext.IntegrityValidator = new IntegrityValidator(testChainContext.ConsensusRules, testChainContext.LoggerFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public CachedCoinView(Network network, ICheckpoints checkpoints, ICoindb coindb,
this.MaxCacheSizeBytes = consensusSettings.MaxCoindbCacheInMB * 1024 * 1024;
this.CacheFlushTimeIntervalSeconds = consensusSettings.CoindbIbdFlushMin * 60;

nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 300);
if (nodeStats.DisplayBenchStats)
nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 300);
}

public HashHeightPair GetTipHash()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DBreezeCoindb : ICoindb, IStakedb, IDisposable
/// <summary>Access to dBreeze database.</summary>
private readonly DBreezeEngine dBreeze;

private DBreezeSerializer dBreezeSerializer;
private readonly DBreezeSerializer dBreezeSerializer;

public DBreezeCoindb(Network network, DataFolder dataFolder, IDateTimeProvider dateTimeProvider,
ILoggerFactory loggerFactory, INodeStats nodeStats, DBreezeSerializer dBreezeSerializer)
Expand All @@ -61,7 +61,8 @@ public DBreezeCoindb(Network network, string folder, IDateTimeProvider dateTimeP
this.network = network;
this.performanceCounter = new BackendPerformanceCounter(dateTimeProvider);

nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 400);
if (nodeStats.DisplayBenchStats)
nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 300);
}

public void Initialize()
Expand Down Expand Up @@ -343,7 +344,7 @@ public void GetStake(IEnumerable<StakeItem> blocklist)

private void AddBenchStats(StringBuilder log)
{
log.AppendLine("======DBreezeCoinView Bench======");
log.AppendLine(">> DBreezeCoinView Bench");

BackendPerformanceSnapshot snapShot = this.performanceCounter.Snapshot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class FasterCoindb : ICoindb, IStakedb, IDisposable

private BackendPerformanceSnapshot latestPerformanceSnapShot;

private DBreezeSerializer dBreezeSerializer;
private readonly DBreezeSerializer dBreezeSerializer;

private string dataFolder;
private readonly string dataFolder;

public FasterKV<Types.StoreKey, Types.StoreValue, Types.StoreInput, Types.StoreOutput, Types.StoreContext, Types.StoreFunctions> db;
public IDevice log;
Expand All @@ -60,7 +60,8 @@ public FasterCoindb(Network network, string folder, IDateTimeProvider dateTimePr
this.performanceCounter = new BackendPerformanceCounter(dateTimeProvider);
this.dataFolder = folder;

nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 400);
if (nodeStats.DisplayBenchStats)
nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 400);
}

public void Initialize()
Expand Down Expand Up @@ -401,7 +402,7 @@ public HashHeightPair Rewind()

private void AddBenchStats(StringBuilder log)
{
log.AppendLine("======Faster Bench======");
log.AppendLine(">> Faster Bench");

BackendPerformanceSnapshot snapShot = this.performanceCounter.Snapshot();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LeveldbCoindb : ICoindb, IStakedb, IDisposable
/// <summary>Access to dBreeze database.</summary>
private readonly DB leveldb;

private DBreezeSerializer dBreezeSerializer;
private readonly DBreezeSerializer dBreezeSerializer;

public LeveldbCoindb(Network network, DataFolder dataFolder, IDateTimeProvider dateTimeProvider,
ILoggerFactory loggerFactory, INodeStats nodeStats, DBreezeSerializer dBreezeSerializer)
Expand All @@ -65,7 +65,8 @@ public LeveldbCoindb(Network network, string folder, IDateTimeProvider dateTimeP
this.network = network;
this.performanceCounter = new BackendPerformanceCounter(dateTimeProvider);

nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 400);
if (nodeStats.DisplayBenchStats)
nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 400);
}

public void Initialize()
Expand Down Expand Up @@ -273,7 +274,7 @@ public void GetStake(IEnumerable<StakeItem> blocklist)

private void AddBenchStats(StringBuilder log)
{
log.AppendLine("======Leveldb Bench======");
log.AppendLine(">> Leveldb Bench");

BackendPerformanceSnapshot snapShot = this.performanceCounter.Snapshot();

Expand Down
Loading

0 comments on commit c48a780

Please sign in to comment.