From 60aed9540026a81260ee93820ea3d8633d5a673d Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 26 Nov 2015 22:05:34 +0100 Subject: [PATCH 1/3] Fix and improve relay from whitelisted peers This makes sure that retransmits by a whitelisted peer also actually result in a retransmit. Further, this changes the logic to never relay in case we would assign a DoS score, as we expect to get DoS banned ourselves as a result. --- src/main.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 082456af2..256f47573 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4659,11 +4659,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, mapAlreadyAskedFor.erase(inv); - // Check for recently rejected (and do other quick existence checks) - if (AlreadyHave(inv)) - return true; - - if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) + if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) { mempool.check(pcoinsTip); RelayTransaction(tx); @@ -4744,13 +4740,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pfrom->fWhitelisted) { // Always relay transactions received from whitelisted peers, even - // if they were rejected from the mempool, allowing the node to - // function as a gateway for nodes hidden behind it. + // if they were already in the mempool or rejected from it due + // to policy, allowing the node to function as a gateway for + // nodes hidden behind it. // - // FIXME: This includes invalid transactions, which means a - // whitelisted peer could get us banned! We may want to change - // that. - RelayTransaction(tx); + // Never relay transactions that we would assign a non-zero DoS + // score for, as we expect peers to do the same with us in that + // case. + int nDoS = 0; + if (!state.IsInvalid(nDoS) || nDoS == 0) { + LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->id); + RelayTransaction(tx); + } else { + LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->id, FormatStateMessage(state)); + } } } int nDoS = 0; From de3dd8a0157bbd03e5737701a719ce54aa8ab232 Mon Sep 17 00:00:00 2001 From: Date: Fri, 16 Sep 2016 17:51:46 -0700 Subject: [PATCH 2/3] Modify message string so we don't need to backport commits which implement FormatStateMessage and GetDebugMessage and involve changes to consensus/validation.h --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 256f47573..c5b333c5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4752,7 +4752,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->id); RelayTransaction(tx); } else { - LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->id, FormatStateMessage(state)); + LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s (code %i))\n", + tx.GetHash().ToString(), pfrom->id, state.GetRejectReason(), state.GetRejectCode()); } } } From e63d14fd4d115158fef8eb0314908cf7184d7811 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 19 Sep 2016 09:36:26 -0700 Subject: [PATCH 3/3] Replace %i format specifier with more commonly used %d. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c5b333c5a..3badc9ae3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4752,7 +4752,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->id); RelayTransaction(tx); } else { - LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s (code %i))\n", + LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s (code %d))\n", tx.GetHash().ToString(), pfrom->id, state.GetRejectReason(), state.GetRejectCode()); } }