Skip to content

Commit 35550a3

Browse files
authored
Add quorumModifierHash to instant send lock vote (#2505)
* Let GetMasternodeRank also return the block hash at the given height * Add outpointConfirmedBlock to CTxLockVote and verify it * Match order of parameters with member order * Rename outpointConfirmedBlock to quorumModifierHash * Add overload of GetMasternodeRank that does not return the block hash
1 parent 812834d commit 35550a3

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

src/instantx.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,16 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
244244
int nLockInputHeight = nPrevoutHeight + Params().GetConsensus().nInstantSendConfirmationsRequired - 2;
245245

246246
int nRank;
247+
uint256 quorumModifierHash;
247248
int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto());
248-
if (!mnodeman.GetMasternodeRank(activeMasternodeInfo.outpoint, nRank, nLockInputHeight, nMinRequiredProtocol)) {
249+
if (!mnodeman.GetMasternodeRank(activeMasternodeInfo.outpoint, nRank, quorumModifierHash, nLockInputHeight, nMinRequiredProtocol)) {
249250
LogPrint("instantsend", "CInstantSend::Vote -- Can't calculate rank for masternode %s\n", activeMasternodeInfo.outpoint.ToStringShort());
250251
continue;
251252
}
253+
if (!deterministicMNManager->IsDeterministicMNsSporkActive()) {
254+
// not used until spork15 activation
255+
quorumModifierHash = uint256();
256+
}
252257

253258
int nSignaturesTotal = COutPointLock::SIGNATURES_TOTAL;
254259
if (nRank > nSignaturesTotal) {
@@ -282,7 +287,7 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
282287

283288
// we haven't voted for this outpoint yet, let's try to do this now
284289
// Please note that activeMasternodeInfo.proTxHash is only valid after spork15 activation
285-
CTxLockVote vote(txHash, outpointLockPair.first, activeMasternodeInfo.outpoint, activeMasternodeInfo.proTxHash);
290+
CTxLockVote vote(txHash, outpointLockPair.first, activeMasternodeInfo.outpoint, quorumModifierHash, activeMasternodeInfo.proTxHash);
286291

287292
if (!vote.Sign()) {
288293
LogPrintf("CInstantSend::Vote -- Failed to sign consensus vote\n");
@@ -1052,12 +1057,23 @@ bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const
10521057
int nLockInputHeight = coin.nHeight + Params().GetConsensus().nInstantSendConfirmationsRequired - 2;
10531058

10541059
int nRank;
1060+
uint256 expectedQuorumModifierHash;
10551061
int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto());
1056-
if (!mnodeman.GetMasternodeRank(outpointMasternode, nRank, nLockInputHeight, nMinRequiredProtocol)) {
1062+
if (!mnodeman.GetMasternodeRank(outpointMasternode, nRank, expectedQuorumModifierHash, nLockInputHeight, nMinRequiredProtocol)) {
10571063
//can be caused by past versions trying to vote with an invalid protocol
10581064
LogPrint("instantsend", "CTxLockVote::IsValid -- Can't calculate rank for masternode %s\n", outpointMasternode.ToStringShort());
10591065
return false;
10601066
}
1067+
if (!quorumModifierHash.IsNull()) {
1068+
if (quorumModifierHash != expectedQuorumModifierHash) {
1069+
LogPrint("instantsend", "CTxLockVote::IsValid -- invalid quorumModifierHash %s, expected %s\n", quorumModifierHash.ToString(), expectedQuorumModifierHash.ToString());
1070+
return false;
1071+
}
1072+
} else if (deterministicMNManager->IsDeterministicMNsSporkActive()) {
1073+
LogPrint("instantsend", "CTxLockVote::IsValid -- missing quorumModifierHash while DIP3 is active\n");
1074+
return false;
1075+
}
1076+
10611077
LogPrint("instantsend", "CTxLockVote::IsValid -- Masternode %s, rank=%d\n", outpointMasternode.ToStringShort(), nRank);
10621078

10631079
int nSignaturesTotal = COutPointLock::SIGNATURES_TOTAL;

src/instantx.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class CTxLockVote
235235
COutPoint outpoint;
236236
// TODO remove this member when the legacy masternode code is removed after DIP3 deployment
237237
COutPoint outpointMasternode;
238+
uint256 quorumModifierHash;
238239
uint256 masternodeProTxHash;
239240
std::vector<unsigned char> vchMasternodeSignature;
240241
// local memory only
@@ -246,16 +247,18 @@ class CTxLockVote
246247
txHash(),
247248
outpoint(),
248249
outpointMasternode(),
250+
quorumModifierHash(),
249251
masternodeProTxHash(),
250252
vchMasternodeSignature(),
251253
nConfirmedHeight(-1),
252254
nTimeCreated(GetTime())
253255
{}
254256

255-
CTxLockVote(const uint256& txHashIn, const COutPoint& outpointIn, const COutPoint& outpointMasternodeIn, const uint256& masternodeProTxHashIn) :
257+
CTxLockVote(const uint256& txHashIn, const COutPoint& outpointIn, const COutPoint& outpointMasternodeIn, const uint256& quorumModifierHashIn, const uint256& masternodeProTxHashIn) :
256258
txHash(txHashIn),
257259
outpoint(outpointIn),
258260
outpointMasternode(outpointMasternodeIn),
261+
quorumModifierHash(quorumModifierHashIn),
259262
masternodeProTxHash(masternodeProTxHashIn),
260263
vchMasternodeSignature(),
261264
nConfirmedHeight(-1),
@@ -270,8 +273,9 @@ class CTxLockVote
270273
READWRITE(outpoint);
271274
READWRITE(outpointMasternode);
272275
if (deterministicMNManager->IsDeterministicMNsSporkActive()) {
273-
// Starting with spork15 activation, the proTxHash is included. When we bump to >= 70213, we can remove
276+
// Starting with spork15 activation, the proTxHash and quorumModifierHash is included. When we bump to >= 70213, we can remove
274277
// the surrounding if. We might also remove outpointMasternode as well later
278+
READWRITE(quorumModifierHash);
275279
READWRITE(masternodeProTxHash);
276280
}
277281
if (!(s.GetType() & SER_GETHASH)) {

src/masternodeman.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,23 +821,29 @@ bool CMasternodeMan::GetMasternodeScores(const uint256& nBlockHash, CMasternodeM
821821
}
822822

823823
bool CMasternodeMan::GetMasternodeRank(const COutPoint& outpoint, int& nRankRet, int nBlockHeight, int nMinProtocol)
824+
{
825+
uint256 tmp;
826+
return GetMasternodeRank(outpoint, nRankRet, tmp, nBlockHeight, nMinProtocol);
827+
}
828+
829+
bool CMasternodeMan::GetMasternodeRank(const COutPoint& outpoint, int& nRankRet, uint256& blockHashRet, int nBlockHeight, int nMinProtocol)
824830
{
825831
nRankRet = -1;
826832

827833
if (!masternodeSync.IsMasternodeListSynced())
828834
return false;
829835

830836
// make sure we know about this block
831-
uint256 nBlockHash = uint256();
832-
if (!GetBlockHash(nBlockHash, nBlockHeight)) {
837+
blockHashRet = uint256();
838+
if (!GetBlockHash(blockHashRet, nBlockHeight)) {
833839
LogPrintf("CMasternodeMan::%s -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", __func__, nBlockHeight);
834840
return false;
835841
}
836842

837843
LOCK(cs);
838844

839845
score_pair_vec_t vecMasternodeScores;
840-
if (!GetMasternodeScores(nBlockHash, vecMasternodeScores, nMinProtocol))
846+
if (!GetMasternodeScores(blockHashRet, vecMasternodeScores, nMinProtocol))
841847
return false;
842848

843849
int nRank = 0;

src/masternodeman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class CMasternodeMan
187187

188188
bool GetMasternodeRanks(rank_pair_vec_t& vecMasternodeRanksRet, int nBlockHeight = -1, int nMinProtocol = 0);
189189
bool GetMasternodeRank(const COutPoint &outpoint, int& nRankRet, int nBlockHeight = -1, int nMinProtocol = 0);
190+
bool GetMasternodeRank(const COutPoint &outpoint, int& nRankRet, uint256& blockHashRet, int nBlockHeight = -1, int nMinProtocol = 0);
190191

191192
void ProcessMasternodeConnections(CConnman& connman);
192193
std::pair<CService, std::set<uint256> > PopScheduledMnbRequestConnection();

0 commit comments

Comments
 (0)