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
10 changes: 5 additions & 5 deletions src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void Initialize()
var uniquePolls = new HashSet<Poll>(polls);
if (uniquePolls.Count != polls.Count)
{
this.logger.Warn("The polls repo contains {0} duplicate polls. Will rebuild it.", polls.Count - uniquePolls.Count);
this.logger.Warn("The polls repository contains {0} duplicate polls, it will be rebuilt.", 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.Info("The polls repository tip is unknown. Will re-build the repo.");
this.logger.Info("The polls repository tip is unknown, it will be rebuilt.");
this.ResetLocked(transaction);
transaction.Commit();
return;
Expand All @@ -92,7 +92,7 @@ public void Initialize()
return;
}

this.logger.Info("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.Info("No common blocks found. Will rebuild the repo from scratch.");
this.logger.Info("No common blocks found; the repo will be rebuil from scratch.");
this.ResetLocked(transaction);
transaction.Commit();
return;
}

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

this.logger.Info("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}; the repo will be rebuilt from there.", this.CurrentTip.Height);

// Trim polls to tip.
HashSet<Poll> pollsToDelete = new HashSet<Poll>();
Expand Down
23 changes: 23 additions & 0 deletions src/Stratis.Bitcoin.Features.PoA/Voting/VotingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ public VotingController(
this.logger = LogManager.GetCurrentClassLogger();
}

/// <summary>
/// Retrieves the tip of the polls repository.
/// </summary>
/// <returns>The poll repository tip.</returns>
/// <response code="200">The request succeeded.</response>
/// <response code="400">Unexpected exception occurred</response>
[Route("polls/tip")]
[HttpGet]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public IActionResult GetPollsRepositoryTip()
{
try
{
return this.Json(this.votingManager.GetPollsRepositoryTip());
}
catch (Exception e)
{
this.logger.Error("Exception occurred: {0}", e.ToString());
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}

/// <summary>
/// Retrieves a list of pending or "active" polls.
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ public sealed class VotingManager : IDisposable

internal bool isInitialized;

public VotingManager(IFederationManager federationManager, IPollResultExecutor pollResultExecutor, INodeStats nodeStats,
DataFolder dataFolder, DBreezeSerializer dBreezeSerializer, ISignals signals, Network network,
public VotingManager(
IFederationManager federationManager,
IPollResultExecutor pollResultExecutor,
INodeStats nodeStats,
DataFolder dataFolder,
DBreezeSerializer dBreezeSerializer,
ISignals signals,
Network network,
IBlockRepository blockRepository = null,
ChainIndexer chainIndexer = null,
INodeLifetime nodeLifetime = null)
Expand Down Expand Up @@ -826,6 +832,7 @@ internal bool Synchronize(ChainedHeader newTip)
if (header.Height % 10000 == 0)
{
this.logger.Info($"Synchronizing voting data at height {header.Height}.");
this.signals.Publish(new FullNodeEvent() { Message = $"Synchronizing voting data at height {header.Height}.", State = FullNodeState.Initializing.ToString() });
}
}

Expand Down