Skip to content

Commit a9aec5c

Browse files
committed
Use BlockChecked signal to send reject messages from mapBlockSource
1 parent 7565e03 commit a9aec5c

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/main.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,17 +1857,6 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
18571857
}
18581858

18591859
void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) {
1860-
int nDoS = 0;
1861-
if (state.IsInvalid(nDoS)) {
1862-
std::map<uint256, NodeId>::iterator it = mapBlockSource.find(pindex->GetBlockHash());
1863-
if (it != mapBlockSource.end() && State(it->second)) {
1864-
assert (state.GetRejectCode() < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
1865-
CBlockReject reject = {(unsigned char)state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), pindex->GetBlockHash()};
1866-
State(it->second)->rejects.push_back(reject);
1867-
if (nDoS > 0)
1868-
Misbehaving(it->second, nDoS);
1869-
}
1870-
}
18711860
if (!state.CorruptionPossible()) {
18721861
pindex->nStatus |= BLOCK_FAILED_VALID;
18731862
setDirtyBlockIndex.insert(pindex);
@@ -2814,7 +2803,6 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
28142803
InvalidBlockFound(pindexNew, state);
28152804
return error("ConnectTip(): ConnectBlock %s failed", pindexNew->GetBlockHash().ToString());
28162805
}
2817-
mapBlockSource.erase(pindexNew->GetBlockHash());
28182806
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
28192807
LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001);
28202808
assert(view.Flush());
@@ -4687,6 +4675,26 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
46874675
}
46884676
}
46894677

4678+
void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationState& state) {
4679+
LOCK(cs_main);
4680+
4681+
const uint256 hash(block.GetHash());
4682+
std::map<uint256, NodeId>::iterator it = mapBlockSource.find(hash);
4683+
4684+
int nDoS = 0;
4685+
if (state.IsInvalid(nDoS)) {
4686+
if (it != mapBlockSource.end() && State(it->second)) {
4687+
assert (state.GetRejectCode() < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
4688+
CBlockReject reject = {(unsigned char)state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), hash};
4689+
State(it->second)->rejects.push_back(reject);
4690+
if (nDoS > 0)
4691+
Misbehaving(it->second, nDoS);
4692+
}
4693+
}
4694+
if (it != mapBlockSource.end())
4695+
mapBlockSource.erase(it);
4696+
}
4697+
46904698
//////////////////////////////////////////////////////////////////////////////
46914699
//
46924700
// Messages

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ class PeerLogicValidation : public CValidationInterface {
536536
PeerLogicValidation(CConnman* connmanIn) : connman(connmanIn) {}
537537

538538
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload);
539+
virtual void BlockChecked(const CBlock& block, const CValidationState& state);
539540
};
540541

541542
struct CNodeStateStats {

0 commit comments

Comments
 (0)