Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

fix: incorrect queue predictions returned by status command #416

Merged
merged 3 commits into from
Aug 17, 2021
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
33 changes: 21 additions & 12 deletions src/commands/status/masternode.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class MasternodeStatusCommand extends ConfigBaseCommand {

const {
result: {
dmnState: masternodeState,
dmnState: masternodeDmnState,
state: masternodeState,
status: masternodeStatus,
proTxHash: masternodeProTxHash,
},
Expand Down Expand Up @@ -92,10 +93,18 @@ class MasternodeStatusCommand extends ConfigBaseCommand {

// Determine payment queue position
let paymentQueuePosition;
if (masternodeStatus === 'Ready' && masternodeState.PoSeRevivedHeight > 0) {
let lastPaidTime;
if (masternodeState === 'READY') {
paymentQueuePosition = getPaymentQueuePosition(
masternodeState, masternodeEnabledCount, coreBlocks,
masternodeDmnState, masternodeEnabledCount, coreBlocks,
);

// Determine last paid time
if (masternodeDmnState.lastPaidHeight === 0) {
lastPaidTime = 'Never';
} else {
lastPaidTime = `${blocksToTime(coreBlocks - masternodeDmnState.lastPaidHeight)} ago`;
}
}

// Apply colors
Expand All @@ -115,23 +124,23 @@ class MasternodeStatusCommand extends ConfigBaseCommand {

let masternodePoSePenalty;
if (masternodeStatus === 'Ready') {
if (masternodeState.PoSePenalty === 0) {
masternodePoSePenalty = chalk.green(masternodeState.PoSePenalty);
} else if (masternodeState.PoSePenalty < masternodeEnabledCount) {
masternodePoSePenalty = chalk.yellow(masternodeState.PoSePenalty);
if (masternodeDmnState.PoSePenalty === 0) {
masternodePoSePenalty = chalk.green(masternodeDmnState.PoSePenalty);
} else if (masternodeDmnState.PoSePenalty < masternodeEnabledCount) {
masternodePoSePenalty = chalk.yellow(masternodeDmnState.PoSePenalty);
} else {
masternodePoSePenalty = chalk.red(masternodeState.PoSePenalty);
masternodePoSePenalty = chalk.red(masternodeDmnState.PoSePenalty);
}
}

// Build table
rows.push(['Masternode status', (masternodeStatus === 'Ready' ? chalk.green : chalk.red)(masternodeStatus)]);
rows.push(['Masternode status', (masternodeState === 'READY' ? chalk.green : chalk.red)(masternodeStatus)]);
rows.push(['Sentinel status', (sentinelState !== '' ? sentinelState : 'No errors')]);
if (masternodeStatus === 'Ready') {
if (masternodeState === 'READY') {
rows.push(['ProTx Hash', masternodeProTxHash]);
rows.push(['PoSe Penalty', masternodePoSePenalty]);
rows.push(['Last paid block', masternodeState.lastPaidHeight]);
rows.push(['Last paid time', `${blocksToTime(coreBlocks - masternodeState.lastPaidHeight)} ago`]);
rows.push(['Last paid block', masternodeDmnState.lastPaidHeight]);
rows.push(['Last paid time', lastPaidTime]);
rows.push(['Payment queue position', `${paymentQueuePosition}/${masternodeEnabledCount}`]);
rows.push(['Next payment time', `in ${blocksToTime(paymentQueuePosition)}`]);
}
Expand Down
5 changes: 4 additions & 1 deletion src/util/getPaymentQueuePosition.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
function getPaymentQueuePosition(masternodeState, masternodeEnabledCount, coreBlocks) {
let paymentQueuePosition;
if (masternodeState.PoSeRevivedHeight > coreBlocks) {
// Masternode has been unbanned recently
if (masternodeState.PoSeRevivedHeight > masternodeState.lastPaidHeight) {
paymentQueuePosition = masternodeState.PoSeRevivedHeight
+ masternodeEnabledCount
- coreBlocks;
// Masternode has never been paid
} else if (masternodeState.lastPaidHeight === 0) {
paymentQueuePosition = masternodeState.registeredHeight
+ masternodeEnabledCount
- coreBlocks;
// Masternode was previously paid and is in normal queue
} else {
paymentQueuePosition = masternodeState.lastPaidHeight
+ masternodeEnabledCount
Expand Down