Skip to content

Commit

Permalink
Include masternodeProTxHash in CTxLockVote (#2484)
Browse files Browse the repository at this point in the history
* Introduce proTxHash to CActiveMasternodeInfo

* Include masternodeProTxHash in CTxLockVote
  • Loading branch information
codablock authored Nov 23, 2018
1 parent aa49540 commit fa8f4a1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void CActiveDeterministicMasternodeManager::Init()
return;
}

activeMasternodeInfo.proTxHash = mnListEntry->proTxHash;
activeMasternodeInfo.outpoint = mnListEntry->collateralOutpoint;
state = MASTERNODE_READY;
}
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/activemasternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct CActiveMasternodeInfo {
std::unique_ptr<CBLSSecretKey> blsKeyOperator;

// Initialized while registering Masternode
uint256 proTxHash;
COutPoint outpoint;
CService service;
};
Expand Down
16 changes: 15 additions & 1 deletion src/instantx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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());
Expand Down
13 changes: 12 additions & 1 deletion src/instantx.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "net.h"
#include "primitives/transaction.h"

#include "evo/deterministicmns.h"

class CTxLockVote;
class COutPointLock;
class CTxLockRequest;
Expand Down Expand Up @@ -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
Expand All @@ -242,15 +246,17 @@ class CTxLockVote
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())
Expand All @@ -263,6 +269,11 @@ class CTxLockVote
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);
}
Expand Down

0 comments on commit fa8f4a1

Please sign in to comment.