Skip to content

Commit

Permalink
Bugfix: Don't ban peers just because they have header chains we consi…
Browse files Browse the repository at this point in the history
…der invalid
  • Loading branch information
luke-jr committed Jun 14, 2017
1 parent 228c319 commit 6fda801
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
27 changes: 13 additions & 14 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2260,12 +2260,23 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
LOCK(cs_main);
CNodeState *nodestate = State(pfrom->GetId());

uint256 hashLastBlock;
for (const CBlockHeader& header : headers) {
if (!hashLastBlock.IsNull() && header.hashPrevBlock != hashLastBlock) {
Misbehaving(pfrom->GetId(), 20);
return error("non-continuous headers sequence");
}
hashLastBlock = header.GetHash();
if (!CheckProofOfWork(header.GetHash(), header.nBits, chainparams.GetConsensus())) {
Misbehaving(pfrom->GetId(), 50);
return error("proof of work failed");
}
}

// If this looks like it could be a block announcement (nCount <
// MAX_BLOCKS_TO_ANNOUNCE), use special logic for handling headers that
// don't connect:
// - Send a getheaders message in response to try to connect the chain.
// - The peer can send up to MAX_UNCONNECTING_HEADERS in a row that
// don't connect before giving DoS points
// - Once a headers message is received that is valid and does connect,
// nUnconnectingHeaders gets reset back to 0.
if (mapBlockIndex.find(headers[0].hashPrevBlock) == mapBlockIndex.end() && nCount < MAX_BLOCKS_TO_ANNOUNCE) {
Expand All @@ -2281,20 +2292,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// we can use this peer to download.
UpdateBlockAvailability(pfrom->GetId(), headers.back().GetHash());

if (nodestate->nUnconnectingHeaders % MAX_UNCONNECTING_HEADERS == 0) {
Misbehaving(pfrom->GetId(), 20);
}
return true;
}

uint256 hashLastBlock;
for (const CBlockHeader& header : headers) {
if (!hashLastBlock.IsNull() && header.hashPrevBlock != hashLastBlock) {
Misbehaving(pfrom->GetId(), 20);
return error("non-continuous headers sequence");
}
hashLastBlock = header.GetHash();
}
}

CValidationState state;
Expand Down
3 changes: 0 additions & 3 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ static const bool DEFAULT_FEEFILTER = true;
/** Maximum number of headers to announce when relaying blocks with headers message.*/
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;

/** Maximum number of unconnecting headers announcements before DoS score */
static const int MAX_UNCONNECTING_HEADERS = 10;

static const bool DEFAULT_PEERBLOOMFILTERS = true;

/** Default for -stopatheight */
Expand Down

0 comments on commit 6fda801

Please sign in to comment.