Skip to content

Commit 5ff4db0

Browse files
committed
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.
1 parent 1959f3e commit 5ff4db0

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/net.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "instantx.h"
2929
#include "masternode-sync.h"
3030
#include "privatesend.h"
31+
#include "llmq/quorums_instantsend.h"
3132

3233
#ifdef WIN32
3334
#include <string.h>
@@ -2786,8 +2787,12 @@ bool CConnman::DisconnectNode(NodeId id)
27862787
void CConnman::RelayTransaction(const CTransaction& tx)
27872788
{
27882789
uint256 hash = tx.GetHash();
2789-
int nInv = static_cast<bool>(CPrivateSend::GetDSTX(hash)) ? MSG_DSTX :
2790-
(instantsend.HasTxLockRequest(hash) ? MSG_TXLOCK_REQUEST : MSG_TX);
2790+
int nInv = MSG_TX;
2791+
if (CPrivateSend::GetDSTX(hash)) {
2792+
nInv = MSG_DSTX;
2793+
} else if (llmq::IsOldInstantSendEnabled() && instantsend.HasTxLockRequest(hash)) {
2794+
nInv = MSG_TXLOCK_REQUEST;
2795+
}
27912796
CInv inv(nInv, hash);
27922797
LOCK(cs_vNodes);
27932798
BOOST_FOREACH(CNode* pnode, vNodes)

src/net_processing.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -2015,11 +2015,16 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
20152015
if(strCommand == NetMsgType::TX) {
20162016
vRecv >> ptx;
20172017
txLockRequest = CTxLockRequest(ptx);
2018-
fCanAutoLock = CInstantSend::CanAutoLock() && txLockRequest.IsSimple();
2018+
fCanAutoLock = llmq::IsOldInstantSendEnabled() && CInstantSend::CanAutoLock() && txLockRequest.IsSimple();
20192019
} else if(strCommand == NetMsgType::TXLOCKREQUEST) {
20202020
vRecv >> txLockRequest;
20212021
ptx = txLockRequest.tx;
20222022
nInvType = MSG_TXLOCK_REQUEST;
2023+
if (llmq::IsNewInstantSendEnabled()) {
2024+
// the new system does not require explicit lock requests
2025+
// changing the inv type to MSG_TX also results in re-broadcasting the TX as normal TX
2026+
nInvType = MSG_TX;
2027+
}
20232028
} else if (strCommand == NetMsgType::DSTX) {
20242029
vRecv >> dstx;
20252030
ptx = dstx.tx;
@@ -2035,7 +2040,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
20352040
}
20362041

20372042
// Process custom logic, no matter if tx will be accepted to mempool later or not
2038-
if (strCommand == NetMsgType::TXLOCKREQUEST || fCanAutoLock) {
2043+
if (nInvType == MSG_TXLOCK_REQUEST || fCanAutoLock) {
20392044
if(!instantsend.ProcessTxLockRequest(txLockRequest, connman)) {
20402045
LogPrint("instantsend", "TXLOCKREQUEST -- failed %s\n", txLockRequest.GetHash().ToString());
20412046
// 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
20462051
// Fallback for normal txes to process as usual
20472052
fCanAutoLock = false;
20482053
}
2049-
} else if (strCommand == NetMsgType::DSTX) {
2054+
} else if (nInvType == MSG_DSTX) {
20502055
uint256 hashTx = tx.GetHash();
20512056
if(CPrivateSend::GetDSTX(hashTx)) {
20522057
LogPrint("privatesend", "DSTX -- Already have %s, skipping...\n", hashTx.ToString());
@@ -2083,11 +2088,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
20832088

20842089
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, ptx, true, &fMissingInputs)) {
20852090
// Process custom txes, this changes AlreadyHave to "true"
2086-
if (strCommand == NetMsgType::DSTX) {
2091+
if (nInvType == MSG_DSTX) {
20872092
LogPrintf("DSTX -- Masternode transaction accepted, txid=%s, peer=%d\n",
20882093
tx.GetHash().ToString(), pfrom->id);
20892094
CPrivateSend::AddDSTX(dstx);
2090-
} else if (strCommand == NetMsgType::TXLOCKREQUEST || fCanAutoLock) {
2095+
} else if (nInvType == MSG_TXLOCK_REQUEST || fCanAutoLock) {
20912096
LogPrintf("TXLOCKREQUEST -- Transaction Lock Request accepted, txid=%s, peer=%d\n",
20922097
tx.GetHash().ToString(), pfrom->id);
20932098
instantsend.AcceptLockRequest(txLockRequest);
@@ -2208,7 +2213,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
22082213
}
22092214
}
22102215

2211-
if (strCommand == NetMsgType::TXLOCKREQUEST && !AlreadyHave(inv)) {
2216+
if (nInvType == MSG_TXLOCK_REQUEST && !AlreadyHave(inv)) {
22122217
// i.e. AcceptToMemoryPool failed, probably because it's conflicting
22132218
// with existing normal tx or tx lock for another tx. For the same tx lock
22142219
// AlreadyHave would have return "true" already.

0 commit comments

Comments
 (0)