Guess how far we are in the verification process at the given block index. Since we have signed fixed-interval blocks, estimating progress is a very easy. We can extrapolate the last block time to the current time to estimate how many more blocks we expect.
| 5129 | //! We can extrapolate the last block time to the current time to estimate how many more blocks |
| 5130 | //! we expect. |
| 5131 | double GuessVerificationProgress(const CBlockIndex* pindex, int64_t blockInterval) { |
| 5132 | if (pindex == NULL || pindex->nHeight < 1) { |
| 5133 | return 0.0; |
| 5134 | } |
| 5135 | |
| 5136 | int64_t nNow = GetTime(); |
| 5137 | int64_t moreBlocksExpected = (nNow - pindex->GetBlockTime()) / blockInterval; |
| 5138 | double progress = (pindex->nHeight + 0.0) / (pindex->nHeight + moreBlocksExpected); |
| 5139 | // Round to 3 digits to avoid 0.999999 when finished. |
| 5140 | progress = ceil(progress * 1000.0) / 1000.0; |
| 5141 | // Avoid higher than one if last block is newer than current time. |
| 5142 | return std::min(1.0, progress); |
| 5143 | } |
| 5144 | |
| 5145 | std::optional<uint256> ChainstateManager::SnapshotBlockhash() const |
| 5146 | { |
no test coverage detected