diff --git a/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs b/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs index e1d6b35f5d..f91ea714e8 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs +++ b/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs @@ -69,7 +69,7 @@ public void Initialize() var uniquePolls = new HashSet(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(); @@ -79,7 +79,7 @@ public void Initialize() Row rowTip = transaction.Select(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; @@ -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. @@ -113,7 +113,7 @@ 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; @@ -121,7 +121,7 @@ public void Initialize() 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 pollsToDelete = new HashSet(); diff --git a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingController.cs b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingController.cs index 719e1b0be6..8b04e18664 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingController.cs +++ b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingController.cs @@ -40,6 +40,29 @@ public VotingController( this.logger = LogManager.GetCurrentClassLogger(); } + /// + /// Retrieves the tip of the polls repository. + /// + /// The poll repository tip. + /// The request succeeded. + /// Unexpected exception occurred + [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()); + } + } + /// /// Retrieves a list of pending or "active" polls. /// diff --git a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs index d6464cdc03..63a5d79cbd 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs +++ b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs @@ -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) @@ -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() }); } }