Skip to content

Commit c322652

Browse files
committed
Merge pull request #7046
80ae230 Improve log messages for blocks only violations. (Patick Strateman) 08843ed Add relaytxes status to getpeerinfo (Peter Todd) d8aaa51 Bail early in processing transactions in blocks only mode. (Patick Strateman) 3587f6a Fix relay mechanism for whitelisted peers under blocks only mode. (Patick Strateman)
2 parents 31de241 + 80ae230 commit c322652

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/main.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42114211
return error("message inv size() = %u", vInv.size());
42124212
}
42134213

4214+
bool fBlocksOnly = GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
4215+
4216+
// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistalwaysrelay is true
4217+
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY))
4218+
fBlocksOnly = false;
4219+
42144220
LOCK(cs_main);
42154221

42164222
std::vector<CInv> vToFetch;
@@ -4225,9 +4231,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42254231
bool fAlreadyHave = AlreadyHave(inv);
42264232
LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id);
42274233

4228-
if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY))
4229-
pfrom->AskFor(inv);
4230-
42314234
if (inv.type == MSG_BLOCK) {
42324235
UpdateBlockAvailability(pfrom->GetId(), inv.hash);
42334236
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
@@ -4251,6 +4254,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42514254
LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id);
42524255
}
42534256
}
4257+
else
4258+
{
4259+
if (fBlocksOnly)
4260+
LogPrint("net", "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->id);
4261+
else if (!fAlreadyHave && !fImporting && !fReindex)
4262+
pfrom->AskFor(inv);
4263+
}
42544264

42554265
// Track requests for our stuff
42564266
GetMainSignals().Inventory(inv.hash);
@@ -4375,6 +4385,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
43754385

43764386
else if (strCommand == "tx")
43774387
{
4388+
// Stop processing the transaction early if
4389+
// We are in blocks only mode and peer is either not whitelisted or whitelistalwaysrelay is off
4390+
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)))
4391+
{
4392+
LogPrint("net", "transaction sent in violation of protocol peer=%d\n", pfrom->id);
4393+
return true;
4394+
}
4395+
43784396
vector<uint256> vWorkQueue;
43794397
vector<uint256> vEraseQueue;
43804398
CTransaction tx;

src/net.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ void CNode::copyStats(CNodeStats &stats)
617617
{
618618
stats.nodeid = this->GetId();
619619
X(nServices);
620+
X(fRelayTxes);
620621
X(nLastSend);
621622
X(nLastRecv);
622623
X(nTimeConnected);

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class CNodeStats
180180
public:
181181
NodeId nodeid;
182182
uint64_t nServices;
183+
bool fRelayTxes;
183184
int64_t nLastSend;
184185
int64_t nLastRecv;
185186
int64_t nTimeConnected;

src/rpcnet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp)
9090
" \"addr\":\"host:port\", (string) The ip address and port of the peer\n"
9191
" \"addrlocal\":\"ip:port\", (string) local address\n"
9292
" \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n"
93+
" \"relaytxes\":true|false, (boolean) Whether peer has asked us to relay transactions to it\n"
9394
" \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n"
9495
" \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n"
9596
" \"bytessent\": n, (numeric) The total bytes sent\n"
@@ -134,6 +135,7 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp)
134135
if (!(stats.addrLocal.empty()))
135136
obj.push_back(Pair("addrlocal", stats.addrLocal));
136137
obj.push_back(Pair("services", strprintf("%016x", stats.nServices)));
138+
obj.push_back(Pair("relaytxes", stats.fRelayTxes));
137139
obj.push_back(Pair("lastsend", stats.nLastSend));
138140
obj.push_back(Pair("lastrecv", stats.nLastRecv));
139141
obj.push_back(Pair("bytessent", stats.nSendBytes));

0 commit comments

Comments
 (0)