Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix masternode score/rank calculations #1620

Merged
merged 5 commits into from
Sep 14, 2017
Merged

Conversation

UdjinM6
Copy link

@UdjinM6 UdjinM6 commented Sep 13, 2017

This should fix two issues we have with scores/ranks currently:

  • fix CMasternode::CalculateScore vulnerability (2ba68b6);
  • improve mn list consensus (ae762a6).

Speaking of mn list consensus, selecting non-enabled MNs doesn't degrade quorum quality too much because MNs should have 1000 DASH locked anyway and it's morel likely that they have some problems running MN/propagating pings rather than trying to perform a DoS attack this way. On the other hand, ignoring some live data like pings and wds should help us to stabilize mn list much quicker. Also note, these does NOT change the fact that only valid masternodes are voted for being payed (GetNextMasternodeInQueueForPayment), it only affects (extends) the selection of masternodes who are voting.

@UdjinM6 UdjinM6 added this to the 12.2 milestone Sep 13, 2017
@@ -581,103 +581,100 @@ masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vector<COutPoint
return masternode_info_t();
}

int CMasternodeMan::GetMasternodeRank(const COutPoint& outpoint, int nBlockHeight, int nMinProtocol, bool fOnlyActive)
CMasternodeMan::score_pair_m_t CMasternodeMan::GetMasternodeScores(int nBlockHeight, uint256 blockHash, int nMinProtocol)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nBlockHeight is not used in this method

@@ -16,7 +16,7 @@
/** Masternode manager */
CMasternodeMan mnodeman;

const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan-Version-6";
const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan-Version-7";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0b614fe just bumped the version. Is the new bumping really required? Maybe due to people already using the current version on testnet I'd assume.

@@ -90,6 +90,15 @@ bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb)
//
arith_uint256 CMasternode::CalculateScore(const uint256& blockHash)
{
if (fDIP0001LockedInAtTip) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really required to use DIP0001 activation here? IntantSend is disabled via spork at the moment and I'd assume you won't re-enable InstantSend before enough (nearly all) MNs have upgraded? This is completely independent from DIP0001 activation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scores/ranks are also used in few other places and specifically, mn payments. IS spork is the last one to enable (or at least that's how we usually do). Payment enforcement spork should be kept disabled until most of MNs and miners are upgraded AND mn winners list is stable/consistent across network. Switching score algo via payment enforcement spork could be dangerous too, these things should be done separately imo.

So the idea was to use the "middle" state of DIP0001 activation (THRESHOLD_LOCKED_IN) - we should be pretty confident that majority of miners and MNs are upgraded at that point and it should be safe to switch the algo without being banned by the majority of masternodes and/or hashpower.

Alternatively we could introduce some new spork but this algo upgrade is one way only and we should never need to switch new algo off. Hopefully :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't consider the MN payments. So please ignore what I said :)

@codablock
Copy link

Regarding the new score calculation: 👍
If I understand it correct, an attacker has no chance now to prepare a MN collateral TX which would give him a predictable score/rank, as he can not know in advance about the hash that is later used.


// lock is required and should be acquired outside
AssertLockHeld(cs);
LOCK(cs);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulling the locking into this method (instead of forcing the caller to hold it), creates a race condition. This method returns MNs by pointer and not by value. As the caller does not hold the lock anymore, it's not guaranteed that the pointers are still valid.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah, I knew there was a reason why I did this in the first version :D

return -1;
}

LOCK(cs);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above. The loop below may now use stall data.

return vecMasternodeRanks;
}

LOCK(cs);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.


LOCK(cs);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@codablock
Copy link

utACK

@UdjinM6
Copy link
Author

UdjinM6 commented Sep 14, 2017

Rebased. No code changes, no conflicts, just to make sure IS logic is still valid here after #1592 merge. Looks good imo.

@codablock
Copy link

While reviewing both PRs I also tried to find conflicts between both, nothing found.

@UdjinM6
Copy link
Author

UdjinM6 commented Sep 14, 2017

Looks like travis is happy too, merging

@UdjinM6 UdjinM6 merged commit d7a8489 into dashpay:v0.12.2.x Sep 14, 2017
@UdjinM6 UdjinM6 deleted the fixscore branch January 31, 2019 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants