mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
validation: Make ProcessNewBlock*() members of ChainstateManager
This commit is contained in:
@@ -1736,7 +1736,7 @@ inline void static SendBlockTransactions(const CBlock& block, const BlockTransac
|
||||
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp));
|
||||
}
|
||||
|
||||
bool static ProcessHeadersMessage(CNode* pfrom, CConnman* connman, CTxMemPool& mempool, const std::vector<CBlockHeader>& headers, const CChainParams& chainparams, bool via_compact_block)
|
||||
bool static ProcessHeadersMessage(CNode* pfrom, CConnman* connman, ChainstateManager& chainman, CTxMemPool& mempool, const std::vector<CBlockHeader>& headers, const CChainParams& chainparams, bool via_compact_block)
|
||||
{
|
||||
const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
|
||||
size_t nCount = headers.size();
|
||||
@@ -1796,7 +1796,7 @@ bool static ProcessHeadersMessage(CNode* pfrom, CConnman* connman, CTxMemPool& m
|
||||
}
|
||||
|
||||
BlockValidationState state;
|
||||
if (!ProcessNewBlockHeaders(headers, state, chainparams, &pindexLast)) {
|
||||
if (!chainman.ProcessNewBlockHeaders(headers, state, chainparams, &pindexLast)) {
|
||||
if (state.IsInvalid()) {
|
||||
MaybePunishNodeForBlock(pfrom->GetId(), state, via_compact_block, "invalid header received");
|
||||
return false;
|
||||
@@ -2846,7 +2846,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
|
||||
const CBlockIndex *pindex = nullptr;
|
||||
BlockValidationState state;
|
||||
if (!ProcessNewBlockHeaders({cmpctblock.header}, state, chainparams, &pindex)) {
|
||||
if (!chainman.ProcessNewBlockHeaders({cmpctblock.header}, state, chainparams, &pindex)) {
|
||||
if (state.IsInvalid()) {
|
||||
MaybePunishNodeForBlock(pfrom->GetId(), state, /*via_compact_block*/ true, "invalid header via cmpctblock");
|
||||
return true;
|
||||
@@ -2998,7 +2998,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
// the peer if the header turns out to be for an invalid block.
|
||||
// Note that if a peer tries to build on an invalid chain, that
|
||||
// will be detected and the peer will be banned.
|
||||
return ProcessHeadersMessage(pfrom, connman, mempool, {cmpctblock.header}, chainparams, /*via_compact_block=*/true);
|
||||
return ProcessHeadersMessage(pfrom, connman, chainman, mempool, {cmpctblock.header}, chainparams, /*via_compact_block=*/true);
|
||||
}
|
||||
|
||||
if (fBlockReconstructed) {
|
||||
@@ -3018,7 +3018,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
// we have a chain with at least nMinimumChainWork), and we ignore
|
||||
// compact blocks with less work than our tip, it is safe to treat
|
||||
// reconstructed compact blocks as having been requested.
|
||||
ProcessNewBlock(chainparams, pblock, /*fForceProcessing=*/true, &fNewBlock);
|
||||
chainman.ProcessNewBlock(chainparams, pblock, /*fForceProcessing=*/true, &fNewBlock);
|
||||
if (fNewBlock) {
|
||||
pfrom->nLastBlockTime = GetTime();
|
||||
} else {
|
||||
@@ -3108,7 +3108,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
// disk-space attacks), but this should be safe due to the
|
||||
// protections in the compact block handler -- see related comment
|
||||
// in compact block optimistic reconstruction handling.
|
||||
ProcessNewBlock(chainparams, pblock, /*fForceProcessing=*/true, &fNewBlock);
|
||||
chainman.ProcessNewBlock(chainparams, pblock, /*fForceProcessing=*/true, &fNewBlock);
|
||||
if (fNewBlock) {
|
||||
pfrom->nLastBlockTime = GetTime();
|
||||
} else {
|
||||
@@ -3142,7 +3142,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
|
||||
}
|
||||
|
||||
return ProcessHeadersMessage(pfrom, connman, mempool, headers, chainparams, /*via_compact_block=*/false);
|
||||
return ProcessHeadersMessage(pfrom, connman, chainman, mempool, headers, chainparams, /*via_compact_block=*/false);
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::BLOCK)
|
||||
@@ -3171,7 +3171,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||
mapBlockSource.emplace(hash, std::make_pair(pfrom->GetId(), true));
|
||||
}
|
||||
bool fNewBlock = false;
|
||||
ProcessNewBlock(chainparams, pblock, forceProcessing, &fNewBlock);
|
||||
chainman.ProcessNewBlock(chainparams, pblock, forceProcessing, &fNewBlock);
|
||||
if (fNewBlock) {
|
||||
pfrom->nLastBlockTime = GetTime();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user