Skip to content

Commit a9f3d3d

Browse files
committed
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.
1 parent f8a8e27 commit a9f3d3d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/main.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4421,11 +4421,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
44214421

44224422
mapAlreadyAskedFor.erase(inv);
44234423

4424-
// Check for recently rejected (and do other quick existence checks)
4425-
if (AlreadyHave(inv))
4426-
return true;
4427-
4428-
if (AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
4424+
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
44294425
{
44304426
mempool.check(pcoinsTip);
44314427
RelayTransaction(tx);
@@ -4505,13 +4501,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
45054501

45064502
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)) {
45074503
// Always relay transactions received from whitelisted peers, even
4508-
// if they were rejected from the mempool, allowing the node to
4509-
// function as a gateway for nodes hidden behind it.
4504+
// if they were already in the mempool or rejected from it due
4505+
// to policy, allowing the node to function as a gateway for
4506+
// nodes hidden behind it.
45104507
//
4511-
// FIXME: This includes invalid transactions, which means a
4512-
// whitelisted peer could get us banned! We may want to change
4513-
// that.
4514-
RelayTransaction(tx);
4508+
// Never relay transactions that we would assign a non-zero DoS
4509+
// score for, as we expect peers to do the same with us in that
4510+
// case.
4511+
int nDoS = 0;
4512+
if (!state.IsInvalid(nDoS) || nDoS == 0) {
4513+
LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->id);
4514+
RelayTransaction(tx);
4515+
} else {
4516+
LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->id, FormatStateMessage(state));
4517+
}
45154518
}
45164519
}
45174520
int nDoS = 0;

0 commit comments

Comments
 (0)