aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2021-02-15 20:36:38 +0000
committerGitHub <[email protected]>2021-02-15 20:36:38 +0000
commitd117d075a4dd08549c24163d63dbdd7c4980b2d1 (patch)
tree2c612e04ae1e5f9c22df39b565c40191670cc677 /src
parentMerge pull request #1655 from John-Gee/1.14.3-dev (diff)
parentDon't re-check AuxPoW when sending data to peers (diff)
downloaddiscoin-d117d075a4dd08549c24163d63dbdd7c4980b2d1.tar.xz
discoin-d117d075a4dd08549c24163d63dbdd7c4980b2d1.zip
Merge pull request #1676 from shibe2/skipcheckpow
Don't recompute AuxPoW when serving peer requests
Diffstat (limited to 'src')
-rw-r--r--src/chain.cpp4
-rw-r--r--src/chain.h2
-rw-r--r--src/net_processing.cpp12
-rw-r--r--src/validation.cpp20
-rw-r--r--src/validation.h6
5 files changed, 22 insertions, 22 deletions
diff --git a/src/chain.cpp b/src/chain.cpp
index 2ce98818f..e618f0568 100644
--- a/src/chain.cpp
+++ b/src/chain.cpp
@@ -10,7 +10,7 @@ using namespace std;
/* Moved here from the header, because we need auxpow and the logic
becomes more involved. */
-CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParams) const
+CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParams, bool fCheckPOW) const
{
CBlockHeader block;
@@ -21,7 +21,7 @@ CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParam
have to read the actual *header*, not the full block. */
if (block.IsAuxpow())
{
- ReadBlockHeaderFromDisk(block, this, consensusParams);
+ ReadBlockHeaderFromDisk(block, this, consensusParams, fCheckPOW);
return block;
}
diff --git a/src/chain.h b/src/chain.h
index 7b568eebb..882fdd34d 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -263,7 +263,7 @@ public:
return ret;
}
- CBlockHeader GetBlockHeader(const Consensus::Params& consensusParams) const;
+ CBlockHeader GetBlockHeader(const Consensus::Params& consensusParams, bool fCheckPOW = true) const;
uint256 GetBlockHash() const
{
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 1a918f486..1b33d529b 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1037,7 +1037,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
{
// Send block from disk
CBlock block;
- if (!ReadBlockFromDisk(block, (*mi).second, consensusParams))
+ if (!ReadBlockFromDisk(block, (*mi).second, consensusParams, false))
assert(!"cannot load block from disk");
if (inv.type == MSG_BLOCK)
connman.PushMessage(pfrom, msgMaker.Make(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, block));
@@ -1705,7 +1705,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
}
CBlock block;
- bool ret = ReadBlockFromDisk(block, it->second, chainparams.GetConsensus(it->second->nHeight));
+ bool ret = ReadBlockFromDisk(block, it->second, chainparams.GetConsensus(it->second->nHeight), false);
assert(ret);
SendBlockTransactions(block, req, pfrom, connman);
@@ -1748,7 +1748,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), pfrom->id);
for (; pindex; pindex = chainActive.Next(pindex))
{
- vHeaders.push_back(pindex->GetBlockHeader(chainparams.GetConsensus(pindex->nHeight)));
+ vHeaders.push_back(pindex->GetBlockHeader(chainparams.GetConsensus(pindex->nHeight), false));
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
break;
}
@@ -2974,14 +2974,14 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic<bool>& interr
pBestIndex = pindex;
if (fFoundStartingHeader) {
// add this to the headers message
- vHeaders.push_back(pindex->GetBlockHeader(consensusParams));
+ vHeaders.push_back(pindex->GetBlockHeader(consensusParams, false));
} else if (PeerHasHeader(&state, pindex)) {
continue; // keep looking for the first new block
} else if (pindex->pprev == NULL || PeerHasHeader(&state, pindex->pprev)) {
// Peer doesn't have this header but they do have the prior one.
// Start sending headers.
fFoundStartingHeader = true;
- vHeaders.push_back(pindex->GetBlockHeader(consensusParams));
+ vHeaders.push_back(pindex->GetBlockHeader(consensusParams, false));
} else {
// Peer doesn't have this header or the prior one -- nothing will
// connect, so bail out.
@@ -3014,7 +3014,7 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic<bool>& interr
}
if (!fGotBlockFromCache) {
CBlock block;
- bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
+ bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams, false);
assert(ret);
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness);
connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
diff --git a/src/validation.cpp b/src/validation.cpp
index 629442637..c21c78467 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1147,7 +1147,7 @@ bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHea
both a block and its header. */
template<typename T>
-static bool ReadBlockOrHeader(T& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams)
+static bool ReadBlockOrHeader(T& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, bool fCheckPOW)
{
block.SetNull();
@@ -1165,16 +1165,16 @@ static bool ReadBlockOrHeader(T& block, const CDiskBlockPos& pos, const Consensu
}
// Check the header
- if (!CheckAuxPowProofOfWork(block, consensusParams))
+ if (fCheckPOW && !CheckAuxPowProofOfWork(block, consensusParams))
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
return true;
}
template<typename T>
-static bool ReadBlockOrHeader(T& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
+static bool ReadBlockOrHeader(T& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool fCheckPOW)
{
- if (!ReadBlockOrHeader(block, pindex->GetBlockPos(), consensusParams))
+ if (!ReadBlockOrHeader(block, pindex->GetBlockPos(), consensusParams, fCheckPOW))
return false;
if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockOrHeader(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
@@ -1182,19 +1182,19 @@ static bool ReadBlockOrHeader(T& block, const CBlockIndex* pindex, const Consens
return true;
}
-bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams)
+bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, bool fCheckPOW)
{
- return ReadBlockOrHeader(block, pos, consensusParams);
+ return ReadBlockOrHeader(block, pos, consensusParams, fCheckPOW);
}
-bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
+bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool fCheckPOW)
{
- return ReadBlockOrHeader(block, pindex, consensusParams);
+ return ReadBlockOrHeader(block, pindex, consensusParams, fCheckPOW);
}
-bool ReadBlockHeaderFromDisk(CBlockHeader& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
+bool ReadBlockHeaderFromDisk(CBlockHeader& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool fCheckPOW)
{
- return ReadBlockOrHeader(block, pindex, consensusParams);
+ return ReadBlockOrHeader(block, pindex, consensusParams, fCheckPOW);
}
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
diff --git a/src/validation.h b/src/validation.h
index 386979a14..9e7305492 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -476,9 +476,9 @@ public:
/** Functions for disk access for blocks */
bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart);
-bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
-bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
-bool ReadBlockHeaderFromDisk(CBlockHeader& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
+bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, bool fCheckPOW = true);
+bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool fCheckPOW = true);
+bool ReadBlockHeaderFromDisk(CBlockHeader& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool fCheckPOW = true);
/** Functions for validating blocks and updating the block tree */