Skip to content

Commit

Permalink
Downgrade TXLOCKREQUEST to TX when new IX system is active
Browse files Browse the repository at this point in the history
The new system does not require explicit lock requests, so we downgrade
TXLOCKREQUEST to TX and start propagating it instead of the original.
  • Loading branch information
codablock committed Mar 7, 2019
1 parent 1959f3e commit 5ff4db0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "instantx.h"
#include "masternode-sync.h"
#include "privatesend.h"
#include "llmq/quorums_instantsend.h"

#ifdef WIN32
#include <string.h>
Expand Down Expand Up @@ -2786,8 +2787,12 @@ bool CConnman::DisconnectNode(NodeId id)
void CConnman::RelayTransaction(const CTransaction& tx)
{
uint256 hash = tx.GetHash();
int nInv = static_cast<bool>(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)
Expand Down
17 changes: 11 additions & 6 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5ff4db0

Please sign in to comment.