Skip to content

Commit

Permalink
[Dashboard] Slight POA miner stats refactor (#734)
Browse files Browse the repository at this point in the history
* Refactor poa miner last mined block

* Add federation size
  • Loading branch information
fassadlr committed Oct 8, 2021
1 parent eb2a585 commit 348489f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public sealed class FederationMemberDetailedModel : FederationMemberModel
[JsonProperty("rewardEstimatePerBlock")]
public double RewardEstimatePerBlock { get; set; }

[JsonProperty("producedBlockInLastRound")]
public bool ProducedBlockInLastRound { get; set; }

[JsonProperty("federationSize")]
public int FederationSize { get; set; }

[JsonProperty("miningStats")]
public MiningStatisticsModel MiningStatistics { get; set; }
}
Expand Down
15 changes: 6 additions & 9 deletions src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public class PoAMiner : IPoAMiner
this.votingDataEncoder = new VotingDataEncoder();
this.nodeSettings = nodeSettings;

this.miningStatistics = new MiningStatisticsModel();

nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name);
}

Expand Down Expand Up @@ -196,6 +198,8 @@ private async Task CreateBlocksAsync()
continue;
}

this.miningStatistics.LastBlockProducedHeight = chainedHeader.Height;

var builder = new StringBuilder();
builder.AppendLine("<<==============================================================>>");
builder.AppendLine($"Block mined hash : '{chainedHeader}'");
Expand Down Expand Up @@ -461,10 +465,7 @@ private void AddComponentStats(StringBuilder log)

string pubKeyRepresentation = pubKey.ToString().Substring(0, pubKeyTakeCharacters);
if (pubKey == this.federationManager.CurrentFederationKey?.PubKey)
{
pubKeyRepresentation = "█████";
this.miningStatistics.ProducedBlockInLastRound = true;
}

// Mined in this slot?
if (timeHeader == currentHeader.Header.Time)
Expand All @@ -490,7 +491,6 @@ private void AddComponentStats(StringBuilder log)
log.AppendLine();
}

this.miningStatistics.FederationSize = maxDepth;
this.miningStatistics.MinerHits = hitCount;

log.Append("...");
Expand Down Expand Up @@ -518,13 +518,10 @@ public virtual void Dispose()

public sealed class MiningStatisticsModel
{
[JsonProperty(PropertyName = "federationSize")]
public int FederationSize { get; set; }

[JsonProperty(PropertyName = "minerHits")]
public int MinerHits { get; set; }

[JsonProperty(PropertyName = "producedBlockInLastRound")]
public bool ProducedBlockInLastRound { get; set; }
[JsonProperty(PropertyName = "lastBlockProducedHeight")]
public int LastBlockProducedHeight { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@ public IActionResult GetCurrentMemberInfo()
PubKey = this.federationManager.CurrentFederationKey.PubKey.ToHex()
};

ChainedHeader chainTip = this.chainIndexer.Tip;
federationMemberModel.FederationSize = this.federationManager.GetFederationMembers().Count;

KeyValuePair<PubKey, uint> lastActive = this.idleFederationMembersKicker.GetFederationMembersByLastActiveTime().FirstOrDefault(x => x.Key == this.federationManager.CurrentFederationKey.PubKey);
if (lastActive.Key != null)
{
federationMemberModel.LastActiveTime = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(lastActive.Value);
federationMemberModel.PeriodOfInActivity = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(lastActive.Value);

var roundDepth = chainTip.Height - federationMemberModel.FederationSize;
federationMemberModel.ProducedBlockInLastRound = this.poaMiner.MiningStatistics.LastBlockProducedHeight >= roundDepth;
}

// Is this member part of a pending poll
Expand Down

0 comments on commit 348489f

Please sign in to comment.