Skip to content

Commit

Permalink
Merge pull request #7046
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
gmaxwell committed Nov 22, 2015
2 parents 31de241 + 80ae230 commit c322652
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main.cpp
Expand Up @@ -4211,6 +4211,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return error("message inv size() = %u", vInv.size()); return error("message inv size() = %u", vInv.size());
} }


bool fBlocksOnly = GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);

// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistalwaysrelay is true
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY))
fBlocksOnly = false;

LOCK(cs_main); LOCK(cs_main);


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


if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY))
pfrom->AskFor(inv);

if (inv.type == MSG_BLOCK) { if (inv.type == MSG_BLOCK) {
UpdateBlockAvailability(pfrom->GetId(), inv.hash); UpdateBlockAvailability(pfrom->GetId(), inv.hash);
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
Expand All @@ -4251,6 +4254,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id);
} }
} }
else
{
if (fBlocksOnly)
LogPrint("net", "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->id);
else if (!fAlreadyHave && !fImporting && !fReindex)
pfrom->AskFor(inv);
}


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


else if (strCommand == "tx") else if (strCommand == "tx")
{ {
// Stop processing the transaction early if
// We are in blocks only mode and peer is either not whitelisted or whitelistalwaysrelay is off
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)))
{
LogPrint("net", "transaction sent in violation of protocol peer=%d\n", pfrom->id);
return true;
}

vector<uint256> vWorkQueue; vector<uint256> vWorkQueue;
vector<uint256> vEraseQueue; vector<uint256> vEraseQueue;
CTransaction tx; CTransaction tx;
Expand Down
1 change: 1 addition & 0 deletions src/net.cpp
Expand Up @@ -617,6 +617,7 @@ void CNode::copyStats(CNodeStats &stats)
{ {
stats.nodeid = this->GetId(); stats.nodeid = this->GetId();
X(nServices); X(nServices);
X(fRelayTxes);
X(nLastSend); X(nLastSend);
X(nLastRecv); X(nLastRecv);
X(nTimeConnected); X(nTimeConnected);
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Expand Up @@ -180,6 +180,7 @@ class CNodeStats
public: public:
NodeId nodeid; NodeId nodeid;
uint64_t nServices; uint64_t nServices;
bool fRelayTxes;
int64_t nLastSend; int64_t nLastSend;
int64_t nLastRecv; int64_t nLastRecv;
int64_t nTimeConnected; int64_t nTimeConnected;
Expand Down
2 changes: 2 additions & 0 deletions src/rpcnet.cpp
Expand Up @@ -90,6 +90,7 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp)
" \"addr\":\"host:port\", (string) The ip address and port of the peer\n" " \"addr\":\"host:port\", (string) The ip address and port of the peer\n"
" \"addrlocal\":\"ip:port\", (string) local address\n" " \"addrlocal\":\"ip:port\", (string) local address\n"
" \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n" " \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n"
" \"relaytxes\":true|false, (boolean) Whether peer has asked us to relay transactions to it\n"
" \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n" " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n"
" \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n" " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n"
" \"bytessent\": n, (numeric) The total bytes sent\n" " \"bytessent\": n, (numeric) The total bytes sent\n"
Expand Down Expand Up @@ -134,6 +135,7 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp)
if (!(stats.addrLocal.empty())) if (!(stats.addrLocal.empty()))
obj.push_back(Pair("addrlocal", stats.addrLocal)); obj.push_back(Pair("addrlocal", stats.addrLocal));
obj.push_back(Pair("services", strprintf("%016x", stats.nServices))); obj.push_back(Pair("services", strprintf("%016x", stats.nServices)));
obj.push_back(Pair("relaytxes", stats.fRelayTxes));
obj.push_back(Pair("lastsend", stats.nLastSend)); obj.push_back(Pair("lastsend", stats.nLastSend));
obj.push_back(Pair("lastrecv", stats.nLastRecv)); obj.push_back(Pair("lastrecv", stats.nLastRecv));
obj.push_back(Pair("bytessent", stats.nSendBytes)); obj.push_back(Pair("bytessent", stats.nSendBytes));
Expand Down

0 comments on commit c322652

Please sign in to comment.