| 175 | } |
| 176 | |
| 177 | bool HeadersSyncState::ValidateAndProcessSingleHeader(const CBlockHeader& current) |
| 178 | { |
| 179 | Assume(m_download_state == State::PRESYNC); |
| 180 | if (m_download_state != State::PRESYNC) return false; |
| 181 | |
| 182 | int next_height = m_current_height + 1; |
| 183 | |
| 184 | // Verify that the difficulty isn't growing too fast; an adversary with |
| 185 | // limited hashing capability has a greater chance of producing a high |
| 186 | // work chain if they compress the work into as few blocks as possible, |
| 187 | // so don't let anyone give a chain that would violate the difficulty |
| 188 | // adjustment maximum. |
| 189 | if (!PermittedDifficultyTransition(m_consensus_params, next_height, |
| 190 | m_last_header_received.nBits, current.nBits)) { |
| 191 | LogDebug(BCLog::NET, "Initial headers sync aborted with peer=%d: invalid difficulty transition at height=%i (presync phase)\n", m_id, next_height); |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | if (next_height % m_params.commitment_period == m_commit_offset) { |
| 196 | // Add a commitment. |
| 197 | m_header_commitments.push_back(m_hasher(current.GetHash()) & 1); |
| 198 | if (m_header_commitments.size() > m_max_commitments) { |
| 199 | // The peer's chain is too long; give up. |
| 200 | // It's possible the chain grew since we started the sync; so |
| 201 | // potentially we could succeed in syncing the peer's chain if we |
| 202 | // try again later. |
| 203 | LogDebug(BCLog::NET, "Initial headers sync aborted with peer=%d: exceeded max commitments at height=%i (presync phase)\n", m_id, next_height); |
| 204 | return false; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | m_current_chain_work += GetBlockProof(current); |
| 209 | m_last_header_received = current; |
| 210 | m_current_height = next_height; |
| 211 | |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | bool HeadersSyncState::ValidateAndStoreRedownloadedHeader(const CBlockHeader& header) |
| 216 | { |
nothing calls this directly
no test coverage detected