Skip to content

Commit

Permalink
fix: missed blocks count (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo committed Dec 1, 2020
1 parent b4a0f73 commit 5da6d1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/DTO/Slot.php
Expand Up @@ -4,7 +4,6 @@

namespace App\DTO;

use App\Actions\CacheNetworkHeight;
use App\Services\Monitor\Monitor;
use App\ViewModels\WalletViewModel;
use Carbon\Carbon;
Expand Down Expand Up @@ -106,11 +105,12 @@ public function keepsMissing(): bool

public function missedCount(): int
{
// TODO: this means it will incorrectly show 0 for delegates that missed every block since they got voted in
if ($this->getLastHeight() === 0) {
return 0;
}

return abs(CacheNetworkHeight::execute() - $this->getLastHeight());
return $this->roundNumber - Monitor::roundNumberFromHeight($this->getLastHeight());
}

public function isDone(): bool
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/DTO/SlotTest.php
Expand Up @@ -56,3 +56,20 @@
expect($subject->keepsMissing())->toBeFalse();
expect($subject->missedCount())->toBe(0);
});

it('should show the correct missed blocks amount when spanning multiple rounds', function () {
configureExplorerDatabase();

$wallet = Wallet::factory()->create();

$subject = new Slot([
'publicKey' => $wallet->public_key,
'last_block' => [
'publicKey' => $wallet->public_key,
'height' => 1,
],
'status' => 'done',
], Block::whereBetween('height', [1, 5])->get(), 10);

expect($subject->missedCount())->toBe(9);
});

0 comments on commit 5da6d1a

Please sign in to comment.