From fa8f4a10ccb64dced89afd51907b0719bc379d7e Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 23 Nov 2018 16:33:45 +0100 Subject: [PATCH] Include masternodeProTxHash in CTxLockVote (#2484) * Introduce proTxHash to CActiveMasternodeInfo * Include masternodeProTxHash in CTxLockVote --- src/activemasternode.cpp | 2 ++ src/activemasternode.h | 1 + src/instantx.cpp | 16 +++++++++++++++- src/instantx.h | 13 ++++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index b13437a8d..f24cb942c 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -94,6 +94,7 @@ void CActiveDeterministicMasternodeManager::Init() return; } + activeMasternodeInfo.proTxHash = mnListEntry->proTxHash; activeMasternodeInfo.outpoint = mnListEntry->collateralOutpoint; state = MASTERNODE_READY; } @@ -113,6 +114,7 @@ void CActiveDeterministicMasternodeManager::UpdatedBlockTip(const CBlockIndex* p if (!mnList.IsMNValid(mnListEntry->proTxHash)) { // MN disappeared from MN list state = MASTERNODE_REMOVED; + activeMasternodeInfo.proTxHash = uint256(); activeMasternodeInfo.outpoint.SetNull(); // MN might have reappeared in same block with a new ProTx (with same masternode key) Init(); diff --git a/src/activemasternode.h b/src/activemasternode.h index 7b3ef4500..690629c68 100644 --- a/src/activemasternode.h +++ b/src/activemasternode.h @@ -37,6 +37,7 @@ struct CActiveMasternodeInfo { std::unique_ptr blsKeyOperator; // Initialized while registering Masternode + uint256 proTxHash; COutPoint outpoint; CService service; }; diff --git a/src/instantx.cpp b/src/instantx.cpp index 2fc415db0..a8fe3f982 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -281,7 +281,8 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman) } // we haven't voted for this outpoint yet, let's try to do this now - CTxLockVote vote(txHash, outpointLockPair.first, activeMasternodeInfo.outpoint); + // Please note that activeMasternodeInfo.proTxHash is only valid after spork15 activation + CTxLockVote vote(txHash, outpointLockPair.first, activeMasternodeInfo.outpoint, activeMasternodeInfo.proTxHash); if (!vote.Sign()) { LogPrintf("CInstantSend::Vote -- Failed to sign consensus vote\n"); @@ -1029,6 +1030,19 @@ bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const return false; } + // Verify that masternodeProTxHash belongs to the same MN referred by the collateral + // Only v13 nodes will send us locks with this field set, and only after spork15 activation + if (!masternodeProTxHash.IsNull()) { + masternode_info_t mnInfo; + if (!mnodeman.GetMasternodeInfo(masternodeProTxHash, mnInfo) || mnInfo.outpoint != outpointMasternode) { + LogPrint("instantsend", "CTxLockVote::IsValid -- invalid masternodeProTxHash %s\n", masternodeProTxHash.ToString()); + return false; + } + } else if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + LogPrint("instantsend", "CTxLockVote::IsValid -- missing masternodeProTxHash while DIP3 is active\n"); + return false; + } + Coin coin; if (!GetUTXOCoin(outpoint, coin)) { LogPrint("instantsend", "CTxLockVote::IsValid -- Failed to find UTXO %s\n", outpoint.ToStringShort()); diff --git a/src/instantx.h b/src/instantx.h index 15b60868b..db0f0f12c 100644 --- a/src/instantx.h +++ b/src/instantx.h @@ -8,6 +8,8 @@ #include "net.h" #include "primitives/transaction.h" +#include "evo/deterministicmns.h" + class CTxLockVote; class COutPointLock; class CTxLockRequest; @@ -231,7 +233,9 @@ class CTxLockVote private: uint256 txHash; COutPoint outpoint; + // TODO remove this member when the legacy masternode code is removed after DIP3 deployment COutPoint outpointMasternode; + uint256 masternodeProTxHash; std::vector vchMasternodeSignature; // local memory only int nConfirmedHeight; ///< When corresponding tx is 0-confirmed or conflicted, nConfirmedHeight is -1 @@ -242,15 +246,17 @@ public: txHash(), outpoint(), outpointMasternode(), + masternodeProTxHash(), vchMasternodeSignature(), nConfirmedHeight(-1), nTimeCreated(GetTime()) {} - CTxLockVote(const uint256& txHashIn, const COutPoint& outpointIn, const COutPoint& outpointMasternodeIn) : + CTxLockVote(const uint256& txHashIn, const COutPoint& outpointIn, const COutPoint& outpointMasternodeIn, const uint256& masternodeProTxHashIn) : txHash(txHashIn), outpoint(outpointIn), outpointMasternode(outpointMasternodeIn), + masternodeProTxHash(masternodeProTxHashIn), vchMasternodeSignature(), nConfirmedHeight(-1), nTimeCreated(GetTime()) @@ -263,6 +269,11 @@ public: READWRITE(txHash); READWRITE(outpoint); READWRITE(outpointMasternode); + if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + // Starting with spork15 activation, the proTxHash is included. When we bump to >= 70213, we can remove + // the surrounding if. We might also remove outpointMasternode as well later + READWRITE(masternodeProTxHash); + } if (!(s.GetType() & SER_GETHASH)) { READWRITE(vchMasternodeSignature); }