Skip to content

Commit

Permalink
Fix console mining slots (#232)
Browse files Browse the repository at this point in the history
* Fix console mining slots

* Refactor

* Make own mining slot more visible

* More characters

* Fix console message

* Add no mining information message
  • Loading branch information
quantumagi authored and fassadlr committed Nov 30, 2020
1 parent 50e3c29 commit fe1c6fb
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,44 +403,59 @@ private void AddComponentStats(StringBuilder log)
log.AppendLine();
log.AppendLine("======PoA Miner======");

if (this.ibdState.IsInitialBlockDownload())
{
log.AppendLine($"Mining information is not available during IBD.");
log.AppendLine();
return;
}

ChainedHeader tip = this.consensusManager.Tip;
ChainedHeader currentHeader = tip;
uint currentTime = currentHeader.Header.Time;

int pubKeyTakeCharacters = 4;
int depthReached = 0;
int pubKeyTakeCharacters = 5;
int hitCount = 0;

List<IFederationMember> modifiedFederation = this.votingManager?.GetModifiedFederation(currentHeader) ?? this.federationManager.GetFederationMembers();

int maxDepth = modifiedFederation.Count;

log.AppendLine($"Mining information for the last {maxDepth} blocks.");
log.AppendLine("MISS means that miner didn't produce a block at the timestamp he was supposed to.");
log.AppendLine($"Mining information for the last { maxDepth } blocks.");
log.AppendLine("Note that '<' and '>' surrounds a slot where a miner didn't produce a block.");

uint timeHeader = (uint)this.dateTimeProvider.GetAdjustedTimeAsUnixTimestamp();
timeHeader -= timeHeader % this.network.ConsensusOptions.TargetSpacingSeconds;
if (timeHeader < currentHeader.Header.Time)
timeHeader += this.network.ConsensusOptions.TargetSpacingSeconds;

for (int i = tip.Height; (i > 0) && (i > tip.Height - maxDepth); i--)
// Iterate mining slots.
for (int i = 0; i < maxDepth; i++)
{
// Add stats for current header.
string pubKeyRepresentation = this.slotsManager.GetFederationMemberForTimestamp(currentHeader.Header.Time, modifiedFederation).PubKey.ToString().Substring(0, pubKeyTakeCharacters);
int headerSlot = (int)(timeHeader / this.network.ConsensusOptions.TargetSpacingSeconds) % modifiedFederation.Count;

log.Append("[" + pubKeyRepresentation + "]-");
depthReached++;
hitCount++;
PubKey pubKey = modifiedFederation[headerSlot].PubKey;

currentHeader = currentHeader.Previous;
currentTime -= this.network.ConsensusOptions.TargetSpacingSeconds;
string pubKeyRepresentation = (pubKey == this.federationManager.CurrentFederationKey?.PubKey) ? "█████" : pubKey.ToString().Substring(0, pubKeyTakeCharacters);

if (currentHeader.Height == 0)
break;
// Mined in this slot?
if (timeHeader == currentHeader.Header.Time)
{
log.Append($"[{ pubKeyRepresentation }] ");

currentHeader = currentHeader.Previous;
hitCount++;

while ((currentHeader.Header.Time != currentTime) && (depthReached <= maxDepth))
modifiedFederation = this.votingManager?.GetModifiedFederation(currentHeader) ?? this.federationManager.GetFederationMembers();
}
else
{
log.Append("MISS-");
currentTime -= this.network.ConsensusOptions.TargetSpacingSeconds;
depthReached++;
log.Append($"<{ pubKeyRepresentation }> ");
}

if (depthReached >= maxDepth)
break;
timeHeader -= this.network.ConsensusOptions.TargetSpacingSeconds;

if ((i % 20) == 19)
log.AppendLine();
}

log.Append("...");
Expand Down

0 comments on commit fe1c6fb

Please sign in to comment.