-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[p2p] Send the correct error code in reject messages #10135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1914,7 +1914,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin | |
REJECT_INVALID, "bad-cb-amount"); | ||
|
||
if (!control.Wait()) | ||
return state.DoS(100, false); | ||
return state.DoS(100, error("%s: CheckQueue failed", __func__), REJECT_INVALID, "block-validation-failed"); | ||
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime2; | ||
LogPrint("bench", " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs]\n", nInputs - 1, 0.001 * (nTime4 - nTime2), nInputs <= 1 ? 0 : 0.001 * (nTime4 - nTime2) / (nInputs-1), nTimeVerify * 0.000001); | ||
|
||
|
@@ -2881,10 +2881,12 @@ static bool CheckIndexAgainstCheckpoint(const CBlockIndex* pindexPrev, CValidati | |
return true; | ||
|
||
int nHeight = pindexPrev->nHeight+1; | ||
// Don't accept any forks from the main chain prior to last checkpoint | ||
// Don't accept any forks from the main chain prior to last checkpoint. | ||
// GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our | ||
// MapBlockIndex. | ||
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainparams.Checkpoints()); | ||
if (pcheckpoint && nHeight < pcheckpoint->nHeight) | ||
return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d)", __func__, nHeight)); | ||
return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d)", __func__, nHeight), REJECT_CHECKPOINT, "bad-fork-prior-to-checkpoint"); | ||
|
||
return true; | ||
} | ||
|
@@ -3083,7 +3085,7 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state | |
CBlockIndex* pindexPrev = NULL; | ||
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); | ||
if (mi == mapBlockIndex.end()) | ||
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); | ||
return state.DoS(10, error("%s: prev block not found", __func__), 0, "prev-blk-not-found"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I didn't think of this before, but perhaps we were sending a reject message here specifically because we're assigning DoS points. Suppressing the reject message will just cause the peer to have less information about why they're being disconnected. I'm not sure I think BIP 61 is a great idea (in particular, the lack of versioning makes things difficult) but the motivation of it was in part to let peers know why they're being banned. So maybe it makes more sense to use a REJECT_INVALID message here, rather than omit the reject message altogether, even though the block might not actually be invalid if its missing parent was provided? Really, though, I don't care what we do here, just raising the point in case others have an opinion. Your change here is fine with me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather extend BIP61 than deliberately send a reject message that's incorrect (the block here isn't INVALID, it just doesn't connect with our chain). If you prefer that we send a reject message, I think we should at least change the error code to a 0x4* value and change the message to 'prev-blk-not-found'. |
||
pindexPrev = (*mi).second; | ||
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) | ||
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't feel strongly but we could leave this assert in, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if statement has been modified to check that
state.GetRejectCode() < REJECT_INTERNAL
(so this assert can now never fail)