Skip to content

Commit c894fbb

Browse files
committed
Merge pull request #7106
a9f3d3d Fix and improve relay from whitelisted peers (Pieter Wuille)
2 parents 61457c2 + a9f3d3d commit c894fbb

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/main.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -4610,11 +4610,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46104610

46114611
mapAlreadyAskedFor.erase(inv);
46124612

4613-
// Check for recently rejected (and do other quick existence checks)
4614-
if (AlreadyHave(inv))
4615-
return true;
4616-
4617-
if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
4613+
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
46184614
{
46194615
mempool.check(pcoinsTip);
46204616
RelayTransaction(tx);
@@ -4694,13 +4690,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46944690

46954691
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)) {
46964692
// Always relay transactions received from whitelisted peers, even
4697-
// if they were rejected from the mempool, allowing the node to
4698-
// function as a gateway for nodes hidden behind it.
4693+
// if they were already in the mempool or rejected from it due
4694+
// to policy, allowing the node to function as a gateway for
4695+
// nodes hidden behind it.
46994696
//
4700-
// FIXME: This includes invalid transactions, which means a
4701-
// whitelisted peer could get us banned! We may want to change
4702-
// that.
4703-
RelayTransaction(tx);
4697+
// Never relay transactions that we would assign a non-zero DoS
4698+
// score for, as we expect peers to do the same with us in that
4699+
// case.
4700+
int nDoS = 0;
4701+
if (!state.IsInvalid(nDoS) || nDoS == 0) {
4702+
LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->id);
4703+
RelayTransaction(tx);
4704+
} else {
4705+
LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->id, FormatStateMessage(state));
4706+
}
47044707
}
47054708
}
47064709
int nDoS = 0;

0 commit comments

Comments
 (0)