Skip to content

Commit 89a97a7

Browse files
committed
Merge #17985: net: Remove forcerelay of rejected txs
facb715 net: Remove forcerelay of rejected txs (MarcoFalke) Pull request description: This removes the code that supposedly handled the forced relay of txs from a permissioned peer that were rejected from our mempool. The removal should be fine, because it is dead code for the following reasons: * While `RelayTransaction` enqueues the inv for all peers, the inv is never processed because it can not be found in the mempool. See https://github.com/bitcoin/bitcoin/blob/4a072330763b3ff2d1b5c5b8d30a9517873ac6de/src/net_processing.cpp#L3862-L3866 * Even if the peers we intended to send the inv to can somehow reply with a getdata to the never-received inv, they won't receive the tx as a reply because it was never added to the "relay memory" (`mapRelay`) The dead code is (obviously) untested: https://marcofalke.github.io/btc_cov/total.coverage/src/net_processing.cpp.gcov.html#2574 This feature was (intentionally or accidentally) removed in 4d8993b, which was released in Bitcoin Core 0.13.0. So all currently supported versions of Bitcoin Core ship without this feature. I am not aware of any complaints about this feature or actual documented use-cases. So instead of reviving an unneeded feature, just remove the dead code. ACKs for top commit: hebasto: ACK facb715, locally running the unit and functional tests. Tree-SHA512: bfceae6f2983c1510fa0649a9a63c343cbbc1c4ab3a3698039cccf454c81e58c8f5114b147ed42a1bc867da74c43a5b53764ab14f942e191b6f59079044108b5
2 parents c3b4715 + facb715 commit 89a97a7

File tree

4 files changed

+20
-28
lines changed

4 files changed

+20
-28
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ void SetupServerArgs()
450450
gArgs.AddArg("-whitebind=<[permissions@]addr>", "Bind to given address and whitelist peers connecting to it. "
451451
"Use [host]:port notation for IPv6. Allowed permissions are bloomfilter (allow requesting BIP37 filtered blocks and transactions), "
452452
"noban (do not ban for misbehavior), "
453-
"forcerelay (relay even non-standard transactions), "
453+
"forcerelay (relay transactions that are already in the mempool; implies relay), "
454454
"relay (relay even in -blocksonly mode), "
455455
"and mempool (allow requesting BIP35 mempool contents). "
456456
"Specify multiple permissions separated by commas (default: noban,mempool,relay). Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
@@ -527,7 +527,7 @@ void SetupServerArgs()
527527
gArgs.AddArg("-datacarriersize", strprintf("Maximum size of data in data carrier transactions we relay and mine (default: %u)", MAX_OP_RETURN_RELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
528528
gArgs.AddArg("-minrelaytxfee=<amt>", strprintf("Fees (in %s/kB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)",
529529
CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
530-
gArgs.AddArg("-whitelistforcerelay", strprintf("Add 'forcerelay' permission to whitelisted inbound peers with default permissions. This will relay transactions even if the transactions were already in the mempool or violate local relay policy. (default: %d)", DEFAULT_WHITELISTFORCERELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
530+
gArgs.AddArg("-whitelistforcerelay", strprintf("Add 'forcerelay' permission to whitelisted inbound peers with default permissions. This will relay transactions even if the transactions were already in the mempool. (default: %d)", DEFAULT_WHITELISTFORCERELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
531531
gArgs.AddArg("-whitelistrelay", strprintf("Add 'relay' permission to whitelisted inbound peers with default permissions. This will accept relayed transactions even when not relaying transactions (default: %d)", DEFAULT_WHITELISTRELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
532532

533533

src/net_permissions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum NetPermissionFlags
1515
PF_BLOOMFILTER = (1U << 1),
1616
// Relay and accept transactions from this peer, even if -blocksonly is true
1717
PF_RELAY = (1U << 3),
18-
// Always relay transactions from this peer, even if already in mempool or rejected from policy
18+
// Always relay transactions from this peer, even if already in mempool
1919
// Keep parameter interaction: forcerelay implies relay
2020
PF_FORCERELAY = (1U << 2) | PF_RELAY,
2121
// Can't be banned for misbehavior
@@ -59,4 +59,4 @@ class NetWhitelistPermissions : public NetPermissions
5959
CSubNet m_subnet;
6060
};
6161

62-
#endif // BITCOIN_NET_PERMISSIONS_H
62+
#endif // BITCOIN_NET_PERMISSIONS_H

src/net_processing.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -986,15 +986,6 @@ void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIV
986986
LogPrint(BCLog::NET, "%s: %s peer=%d (%d -> %d)%s\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior, message_prefixed);
987987
}
988988

989-
/**
990-
* Returns true if the given validation state result may result in a peer
991-
* banning/disconnecting us. We use this to determine which unaccepted
992-
* transactions from a whitelisted peer that we can safely relay.
993-
*/
994-
static bool TxRelayMayResultInDisconnect(const TxValidationState& state) {
995-
return state.GetResult() == TxValidationResult::TX_CONSENSUS;
996-
}
997-
998989
/**
999990
* Potentially ban a node based on the contents of a BlockValidationState object
1000991
*
@@ -1064,10 +1055,9 @@ static bool MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& s
10641055
* Potentially ban a node based on the contents of a TxValidationState object
10651056
*
10661057
* @return Returns true if the peer was punished (probably disconnected)
1067-
*
1068-
* Changes here may need to be reflected in TxRelayMayResultInDisconnect().
10691058
*/
1070-
static bool MaybePunishNodeForTx(NodeId nodeid, const TxValidationState& state, const std::string& message = "") {
1059+
static bool MaybePunishNodeForTx(NodeId nodeid, const TxValidationState& state, const std::string& message = "")
1060+
{
10711061
switch (state.GetResult()) {
10721062
case TxValidationResult::TX_RESULT_UNSET:
10731063
break;
@@ -1095,11 +1085,6 @@ static bool MaybePunishNodeForTx(NodeId nodeid, const TxValidationState& state,
10951085
}
10961086

10971087

1098-
1099-
1100-
1101-
1102-
11031088
//////////////////////////////////////////////////////////////////////////////
11041089
//
11051090
// blockchain -> download logic notification
@@ -2615,14 +2600,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
26152600

26162601
if (pfrom->HasPermission(PF_FORCERELAY)) {
26172602
// Always relay transactions received from whitelisted peers, even
2618-
// if they were already in the mempool or rejected from it due
2619-
// to policy, allowing the node to function as a gateway for
2603+
// if they were already in the mempool,
2604+
// allowing the node to function as a gateway for
26202605
// nodes hidden behind it.
2621-
//
2622-
// Never relay transactions that might result in being
2623-
// disconnected (or banned).
2624-
if (state.IsInvalid() && TxRelayMayResultInDisconnect(state)) {
2625-
LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->GetId(), FormatStateMessage(state));
2606+
if (!mempool.exists(tx.GetHash())) {
2607+
LogPrintf("Not relaying non-mempool transaction %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->GetId());
26262608
} else {
26272609
LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->GetId());
26282610
RelayTransaction(tx.GetHash(), *connman);

test/functional/p2p_permissions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ def check_tx_relay(self):
132132
p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1])
133133
wait_until(lambda: txid in self.nodes[0].getrawmempool())
134134

135+
self.log.debug("Check that node[1] will not send an invalid tx to node[0]")
136+
tx.vout[0].nValue += 1
137+
txid = tx.rehash()
138+
p2p_rebroadcast_wallet.send_txs_and_test(
139+
[tx],
140+
self.nodes[1],
141+
success=False,
142+
reject_reason='Not relaying non-mempool transaction {} from whitelisted peer=0'.format(txid),
143+
)
144+
135145
def checkpermission(self, args, expectedPermissions, whitelisted):
136146
self.restart_node(1, args)
137147
connect_nodes(self.nodes[0], 1)

0 commit comments

Comments
 (0)