Include masternodeProTxHash in CTxLockVote (#2484)

* Introduce proTxHash to CActiveMasternodeInfo

* Include masternodeProTxHash in CTxLockVote
This commit is contained in:
Alexander Block 2018-11-23 16:33:45 +01:00 committed by GitHub
parent aa495405b3
commit fa8f4a10cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 2 deletions

View File

@ -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();

View File

@ -37,6 +37,7 @@ struct CActiveMasternodeInfo {
std::unique_ptr<CBLSSecretKey> blsKeyOperator;
// Initialized while registering Masternode
uint256 proTxHash;
COutPoint outpoint;
CService service;
};

View File

@ -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());

View File

@ -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<unsigned char> 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);
}