mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Utilize anti-DoS headers download strategy
Avoid permanently storing headers from a peer, unless the headers are part of a chain with sufficiently high work. This prevents memory attacks using low-work headers. Designed and co-authored with Pieter Wuille.
This commit is contained in:
parent
ed470940cd
commit
551a8d957c
9 changed files with 884 additions and 12 deletions
|
|
@ -3432,6 +3432,22 @@ std::vector<unsigned char> ChainstateManager::GenerateCoinbaseCommitment(CBlock&
|
|||
return commitment;
|
||||
}
|
||||
|
||||
bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams)
|
||||
{
|
||||
return std::all_of(headers.cbegin(), headers.cend(),
|
||||
[&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams);});
|
||||
}
|
||||
|
||||
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers)
|
||||
{
|
||||
arith_uint256 total_work{0};
|
||||
for (const CBlockHeader& header : headers) {
|
||||
CBlockIndex dummy(header);
|
||||
total_work += GetBlockProof(dummy);
|
||||
}
|
||||
return total_work;
|
||||
}
|
||||
|
||||
/** Context-dependent validity checks.
|
||||
* By "context", we mean only the previous block headers, but not the UTXO
|
||||
* set; UTXO-related validity checks are done in ConnectBlock().
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue