Skip to content

Commit e1169d7

Browse files
committed
Merge pull request #3296
a946aa8 Store and use a sanitized subVer (Mike Hearn) ba6a4ea Add some additional logging to give extra network insight. (Mike Hearn)
2 parents 2fc1279 + a946aa8 commit e1169d7

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

src/main.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
797797
g_signals.EraseTransaction(ptxOld->GetHash());
798798
g_signals.SyncTransaction(hash, tx, NULL);
799799

800-
LogPrint("mempool", "AcceptToMemoryPool: : accepted %s (poolsz %"PRIszu")\n",
801-
hash.ToString().c_str(),
802-
pool.mapTx.size());
803800
return true;
804801
}
805802

@@ -3100,8 +3097,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
31003097
pfrom->nVersion = 300;
31013098
if (!vRecv.empty())
31023099
vRecv >> addrFrom >> nNonce;
3103-
if (!vRecv.empty())
3100+
if (!vRecv.empty()) {
31043101
vRecv >> pfrom->strSubVer;
3102+
pfrom->cleanSubVer = SanitizeString(pfrom->strSubVer);
3103+
}
31053104
if (!vRecv.empty())
31063105
vRecv >> pfrom->nStartingHeight;
31073106
if (!vRecv.empty())
@@ -3168,7 +3167,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
31683167

31693168
pfrom->fSuccessfullyConnected = true;
31703169

3171-
LogPrintf("receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
3170+
LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer.c_str(), pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString().c_str(), addrFrom.ToString().c_str(), pfrom->addr.ToString().c_str());
31723171

31733172
AddTimeData(pfrom->addr, nTime);
31743173

@@ -3427,6 +3426,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
34273426
vWorkQueue.push_back(inv.hash);
34283427
vEraseQueue.push_back(inv.hash);
34293428

3429+
3430+
LogPrint("mempool", "AcceptToMemoryPool: %s %s : accepted %s (poolsz %"PRIszu")\n",
3431+
pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
3432+
tx.GetHash().ToString().c_str(),
3433+
mempool.mapTx.size());
3434+
34303435
// Recursively process any orphan transactions that depended on this one
34313436
for (unsigned int i = 0; i < vWorkQueue.size(); i++)
34323437
{
@@ -3475,7 +3480,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
34753480
}
34763481
int nDoS = 0;
34773482
if (state.IsInvalid(nDoS))
3478-
{
3483+
{
3484+
LogPrint("mempool", "%s from %s %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString().c_str(),
3485+
pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str(),
3486+
state.GetRejectReason().c_str());
34793487
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
34803488
state.GetRejectReason(), inv.hash);
34813489
if (nDoS > 0)
@@ -3612,7 +3620,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
36123620
if (!(sProblem.empty())) {
36133621
LogPrint("net", "pong %s %s: %s, %"PRIx64" expected, %"PRIx64" received, %"PRIszu" bytes\n",
36143622
pfrom->addr.ToString().c_str(),
3615-
pfrom->strSubVer.c_str(),
3623+
pfrom->cleanSubVer.c_str(),
36163624
sProblem.c_str(),
36173625
pfrom->nPingNonceSent,
36183626
nonce,

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ void CNode::copyStats(CNodeStats &stats)
616616
X(nTimeConnected);
617617
X(addrName);
618618
X(nVersion);
619-
X(strSubVer);
619+
X(cleanSubVer);
620620
X(fInbound);
621621
X(nStartingHeight);
622622
X(nMisbehavior);

src/net.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class CNodeStats
121121
int64_t nTimeConnected;
122122
std::string addrName;
123123
int nVersion;
124-
std::string strSubVer;
124+
std::string cleanSubVer;
125125
bool fInbound;
126126
int nStartingHeight;
127127
int nMisbehavior;
@@ -203,7 +203,11 @@ class CNode
203203
std::string addrName;
204204
CService addrLocal;
205205
int nVersion;
206-
std::string strSubVer;
206+
// strSubVer is whatever byte array we read from the wire. However, this field is intended
207+
// to be printed out, displayed to humans in various forms and so on. So we sanitize it and
208+
// store the sanitized version in cleanSubVer. The original should be used when dealing with
209+
// the network or wire types and the cleaned string used when displayed or logged.
210+
std::string strSubVer, cleanSubVer;
207211
bool fOneShot;
208212
bool fClient;
209213
bool fInbound;

src/rpcnet.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ Value getpeerinfo(const Array& params, bool fHelp)
126126
if (stats.dPingWait > 0.0)
127127
obj.push_back(Pair("pingwait", stats.dPingWait));
128128
obj.push_back(Pair("version", stats.nVersion));
129-
obj.push_back(Pair("subver", stats.strSubVer));
129+
// Use the sanitized form of subver here, to avoid tricksy remote peers from
130+
// corrupting or modifiying the JSON output by putting special characters in
131+
// their ver message.
132+
obj.push_back(Pair("subver", stats.cleanSubVer));
130133
obj.push_back(Pair("inbound", stats.fInbound));
131134
obj.push_back(Pair("startingheight", stats.nStartingHeight));
132135
obj.push_back(Pair("banscore", stats.nMisbehavior));

0 commit comments

Comments
 (0)