From 5ff4db0a05b15c507e0c3891fbab157f337e70b3 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 28 Feb 2019 13:44:53 +0100 Subject: [PATCH] Downgrade TXLOCKREQUEST to TX when new IX system is active The new system does not require explicit lock requests, so we downgrade TXLOCKREQUEST to TX and start propagating it instead of the original. --- src/net.cpp | 9 +++++++-- src/net_processing.cpp | 17 +++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index fd20a51ee..b54147c02 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -28,6 +28,7 @@ #include "instantx.h" #include "masternode-sync.h" #include "privatesend.h" +#include "llmq/quorums_instantsend.h" #ifdef WIN32 #include @@ -2786,8 +2787,12 @@ bool CConnman::DisconnectNode(NodeId id) void CConnman::RelayTransaction(const CTransaction& tx) { uint256 hash = tx.GetHash(); - int nInv = static_cast(CPrivateSend::GetDSTX(hash)) ? MSG_DSTX : - (instantsend.HasTxLockRequest(hash) ? MSG_TXLOCK_REQUEST : MSG_TX); + int nInv = MSG_TX; + if (CPrivateSend::GetDSTX(hash)) { + nInv = MSG_DSTX; + } else if (llmq::IsOldInstantSendEnabled() && instantsend.HasTxLockRequest(hash)) { + nInv = MSG_TXLOCK_REQUEST; + } CInv inv(nInv, hash); LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index cdd2b522e..1123e9c48 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2015,11 +2015,16 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr if(strCommand == NetMsgType::TX) { vRecv >> ptx; txLockRequest = CTxLockRequest(ptx); - fCanAutoLock = CInstantSend::CanAutoLock() && txLockRequest.IsSimple(); + fCanAutoLock = llmq::IsOldInstantSendEnabled() && CInstantSend::CanAutoLock() && txLockRequest.IsSimple(); } else if(strCommand == NetMsgType::TXLOCKREQUEST) { vRecv >> txLockRequest; ptx = txLockRequest.tx; nInvType = MSG_TXLOCK_REQUEST; + if (llmq::IsNewInstantSendEnabled()) { + // the new system does not require explicit lock requests + // changing the inv type to MSG_TX also results in re-broadcasting the TX as normal TX + nInvType = MSG_TX; + } } else if (strCommand == NetMsgType::DSTX) { vRecv >> dstx; ptx = dstx.tx; @@ -2035,7 +2040,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr } // Process custom logic, no matter if tx will be accepted to mempool later or not - if (strCommand == NetMsgType::TXLOCKREQUEST || fCanAutoLock) { + if (nInvType == MSG_TXLOCK_REQUEST || fCanAutoLock) { if(!instantsend.ProcessTxLockRequest(txLockRequest, connman)) { LogPrint("instantsend", "TXLOCKREQUEST -- failed %s\n", txLockRequest.GetHash().ToString()); // Should not really happen for "fCanAutoLock == true" but just in case: @@ -2046,7 +2051,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr // Fallback for normal txes to process as usual fCanAutoLock = false; } - } else if (strCommand == NetMsgType::DSTX) { + } else if (nInvType == MSG_DSTX) { uint256 hashTx = tx.GetHash(); if(CPrivateSend::GetDSTX(hashTx)) { LogPrint("privatesend", "DSTX -- Already have %s, skipping...\n", hashTx.ToString()); @@ -2083,11 +2088,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, ptx, true, &fMissingInputs)) { // Process custom txes, this changes AlreadyHave to "true" - if (strCommand == NetMsgType::DSTX) { + if (nInvType == MSG_DSTX) { LogPrintf("DSTX -- Masternode transaction accepted, txid=%s, peer=%d\n", tx.GetHash().ToString(), pfrom->id); CPrivateSend::AddDSTX(dstx); - } else if (strCommand == NetMsgType::TXLOCKREQUEST || fCanAutoLock) { + } else if (nInvType == MSG_TXLOCK_REQUEST || fCanAutoLock) { LogPrintf("TXLOCKREQUEST -- Transaction Lock Request accepted, txid=%s, peer=%d\n", tx.GetHash().ToString(), pfrom->id); instantsend.AcceptLockRequest(txLockRequest); @@ -2208,7 +2213,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr } } - if (strCommand == NetMsgType::TXLOCKREQUEST && !AlreadyHave(inv)) { + if (nInvType == MSG_TXLOCK_REQUEST && !AlreadyHave(inv)) { // i.e. AcceptToMemoryPool failed, probably because it's conflicting // with existing normal tx or tx lock for another tx. For the same tx lock // AlreadyHave would have return "true" already.