Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public PoATestsBase(TestPoANetwork network = null)

this.resultExecutorMock = new Mock<IPollResultExecutor>();

this.votingManager = new VotingManager(this.federationManager, this.loggerFactory, this.resultExecutorMock.Object, new NodeStats(dateTimeProvider, NodeSettings.Default(this.network), new Mock<IVersionProvider>().Object),
dataFolder, this.dBreezeSerializer, this.signals, this.network, null, this.chainIndexerMock.Object);
this.votingManager = new VotingManager(this.federationManager, this.resultExecutorMock.Object, new NodeStats(dateTimeProvider, NodeSettings.Default(this.network), new Mock<IVersionProvider>().Object), dataFolder,
this.dBreezeSerializer, this.signals, this.network, null, this.chainIndexerMock.Object);

this.votingManager.Initialize(this.federationHistory);

Expand Down Expand Up @@ -113,8 +113,8 @@ public static (IFederationManager federationManager, IFederationHistory federati
var chainIndexerMock = new Mock<ChainIndexer>();
var header = new BlockHeader();
chainIndexerMock.Setup(x => x.Tip).Returns(new ChainedHeader(header, header.GetHash(), 0));
var votingManager = new VotingManager(federationManager, loggerFactory,
new Mock<IPollResultExecutor>().Object, new Mock<INodeStats>().Object, nodeSettings.DataFolder, dbreezeSerializer, signals, network, null, chainIndexerMock.Object, null);
var votingManager = new VotingManager(federationManager, new Mock<IPollResultExecutor>().Object,
new Mock<INodeStats>().Object, nodeSettings.DataFolder, dbreezeSerializer, signals, network, null, chainIndexerMock.Object, null);

var federationHistory = new Mock<IFederationHistory>();
federationHistory.Setup(x => x.GetFederationMemberForBlock(It.IsAny<ChainedHeader>())).Returns<ChainedHeader>((chainedHeader) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public PollsRepositoryTests()
string dir = TestBase.CreateTestDir(this);
Network network = new TestPoANetwork();

this.repository = new PollsRepository(dir, new ExtendedLoggerFactory(), new DBreezeSerializer(network.Consensus.ConsensusFactory), null);
this.repository = new PollsRepository(dir, new DBreezeSerializer(network.Consensus.ConsensusFactory), null);
this.repository.Initialize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ThrowsIfCantEncode()
[Fact]
public void ThrowsIfEmptyList()
{
var encoder = new VotingDataEncoder(new ExtendedLoggerFactory());
var encoder = new VotingDataEncoder();
byte[] bytes = encoder.Encode(new List<VotingData>());

List<byte> votingData = new List<byte>(VotingDataEncoder.VotingOutputPrefixBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class VotingDataEncoderTests

public VotingDataEncoderTests()
{
this.encoder = new VotingDataEncoder(new ExtendedLoggerFactory());
this.encoder = new VotingDataEncoder();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class VotingManagerTests : PoATestsBase

public VotingManagerTests()
{
this.encoder = new VotingDataEncoder(this.loggerFactory);
this.encoder = new VotingDataEncoder();
this.changesApplied = new List<VotingData>();
this.changesReverted = new List<VotingData>();

Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public PoAMiner(

this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.cancellation = CancellationTokenSource.CreateLinkedTokenSource(new[] { nodeLifetime.ApplicationStopping });
this.votingDataEncoder = new VotingDataEncoder(loggerFactory);
this.votingDataEncoder = new VotingDataEncoder();
this.nodeSettings = nodeSettings;

nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PoAVotingCoinbaseOutputFormatRule : PartialValidationConsensusRule
[NoTrace]
public override void Initialize()
{
this.votingDataEncoder = new VotingDataEncoder(this.Parent.LoggerFactory);
this.votingDataEncoder = new VotingDataEncoder();

base.Initialize();
}
Expand Down
26 changes: 13 additions & 13 deletions src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using DBreeze;
using DBreeze.DataTypes;
using DBreeze.Utils;
using Microsoft.Extensions.Logging;
using NBitcoin;
using NLog;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Utilities;

Expand All @@ -32,20 +32,20 @@ public class PollsRepository : IDisposable

public HashHeightPair CurrentTip { get; private set; }

public PollsRepository(DataFolder dataFolder, ILoggerFactory loggerFactory, DBreezeSerializer dBreezeSerializer, ChainIndexer chainIndexer)
: this(dataFolder.PollsPath, loggerFactory, dBreezeSerializer, chainIndexer)
public PollsRepository(DataFolder dataFolder, DBreezeSerializer dBreezeSerializer, ChainIndexer chainIndexer)
: this(dataFolder.PollsPath, dBreezeSerializer, chainIndexer)
{
}


public PollsRepository(string folder, ILoggerFactory loggerFactory, DBreezeSerializer dBreezeSerializer, ChainIndexer chainIndexer)
public PollsRepository(string folder, DBreezeSerializer dBreezeSerializer, ChainIndexer chainIndexer)
{
Guard.NotEmpty(folder, nameof(folder));

Directory.CreateDirectory(folder);
this.dbreeze = new DBreezeEngine(folder);

this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.logger = LogManager.GetCurrentClassLogger();
this.dBreezeSerializer = dBreezeSerializer;

this.chainIndexer = chainIndexer;
Expand All @@ -60,7 +60,7 @@ public void Initialize()
{
try
{
var polls = GetAllPolls(transaction);
List<Poll> polls = GetAllPolls(transaction);

// If the polls repository contains duplicate polls then reset the highest poll id and
// set the tip to null.
Expand All @@ -69,7 +69,7 @@ public void Initialize()
var uniquePolls = new HashSet<Poll>(polls);
if (uniquePolls.Count != polls.Count)
{
this.logger.LogWarning("The polls repo contains {0} duplicate polls. Will rebuild it.", polls.Count - uniquePolls.Count);
this.logger.Warn("The polls repo contains {0} duplicate polls. Will rebuild it.", polls.Count - uniquePolls.Count);

this.ResetLocked(transaction);
transaction.Commit();
Expand All @@ -79,7 +79,7 @@ public void Initialize()
Row<byte[], byte[]> rowTip = transaction.Select<byte[], byte[]>(DataTable, RepositoryTipKey);
if (!rowTip.Exists)
{
this.logger.LogInformation("The polls repository tip is unknown. Will re-build the repo.");
this.logger.Info("The polls repository tip is unknown. Will re-build the repo.");
this.ResetLocked(transaction);
transaction.Commit();
return;
Expand All @@ -92,7 +92,7 @@ public void Initialize()
return;
}

this.logger.LogInformation("The polls repository tip {0} was not found in the consensus chain. Determining fork.", this.CurrentTip);
this.logger.Info("The polls repository tip {0} was not found in the consensus chain. Determining fork.", this.CurrentTip);

// == Find fork.
// The polls repository tip could not be found in the consenus chain.
Expand All @@ -113,15 +113,15 @@ public void Initialize()

if (maxGoodHeight == -1)
{
this.logger.LogInformation("No common blocks found. Will rebuild the repo from scratch.");
this.logger.Info("No common blocks found. Will rebuild the repo from scratch.");
this.ResetLocked(transaction);
transaction.Commit();
return;
}

this.CurrentTip = new HashHeightPair(this.chainIndexer.GetHeader(maxGoodHeight));

this.logger.LogInformation("Common block found at height {0}. Will re-build the repo from there.", this.CurrentTip.Height);
this.logger.Info("Common block found at height {0}. Will re-build the repo from there.", this.CurrentTip.Height);

// Trim polls to tip.
HashSet<Poll> pollsToDelete = new HashSet<Poll>();
Expand Down Expand Up @@ -161,11 +161,11 @@ public void Initialize()
SaveCurrentTip(transaction, this.CurrentTip);
transaction.Commit();

this.logger.LogDebug("Polls repo initialized with highest id: {0}.", this.highestPollId);
this.logger.Debug("Polls repo initialized with highest id: {0}.", this.highestPollId);
}
catch (Exception err) when (err.Message == "No more byte to read")
{
this.logger.LogWarning("There was an error reading the polls repository. Will rebuild it.");
this.logger.Warn("There was an error reading the polls repository. Will rebuild it.");
this.ResetLocked(transaction);
transaction.Commit();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Stratis.Bitcoin.Features.PoA/Voting/VotingDataEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;
using NBitcoin;
using NLog;

namespace Stratis.Bitcoin.Features.PoA.Voting
{
Expand All @@ -16,9 +16,9 @@ public class VotingDataEncoder

private readonly ILogger logger;

public VotingDataEncoder(ILoggerFactory loggerFactory)
public VotingDataEncoder()
{
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.logger = LogManager.GetCurrentClassLogger();
}

/// <summary>Decodes raw voting data.</summary>
Expand All @@ -29,7 +29,7 @@ public List<VotingData> Decode(byte[] votingDataBytes)
{
if (votingDataBytes.Length > VotingDataMaxSerializedSize)
{
this.logger.LogTrace("(-)[INVALID_SIZE]");
this.logger.Trace("(-)[INVALID_SIZE]");
PoAConsensusErrors.VotingDataInvalidFormat.Throw();
}

Expand All @@ -46,8 +46,8 @@ public List<VotingData> Decode(byte[] votingDataBytes)
}
catch (Exception e)
{
this.logger.LogDebug("Exception during deserialization: '{0}'.", e.ToString());
this.logger.LogTrace("(-)[DESERIALIZING_EXCEPTION]");
this.logger.Debug("Exception during deserialization: '{0}'.", e.ToString());
this.logger.Trace("(-)[DESERIALIZING_EXCEPTION]");

PoAConsensusErrors.VotingDataInvalidFormat.Throw();
return null;
Expand Down Expand Up @@ -93,7 +93,7 @@ public byte[] ExtractRawVotingData(Transaction tx)

if (votingData != null)
{
this.logger.LogTrace("(-)[TOO_MANY_VOTING_OUTPUTS]");
this.logger.Trace("(-)[TOO_MANY_VOTING_OUTPUTS]");
PoAConsensusErrors.TooManyVotingOutputs.Throw();
}

Expand Down
Loading