| 169 | } |
| 170 | |
| 171 | int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params) |
| 172 | { |
| 173 | arith_uint256 r; |
| 174 | int sign = 1; |
| 175 | if (to.nChainWork > from.nChainWork) { |
| 176 | r = to.nChainWork - from.nChainWork; |
| 177 | } else { |
| 178 | r = from.nChainWork - to.nChainWork; |
| 179 | sign = -1; |
| 180 | } |
| 181 | r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip); |
| 182 | if (r.bits() > 63) { |
| 183 | return sign * std::numeric_limits<int64_t>::max(); |
| 184 | } |
| 185 | return sign * int64_t(r.GetLow64()); |
| 186 | } |
| 187 | |
| 188 | /** Find the last common ancestor two blocks have. |
| 189 | * Both pa and pb must be non-nullptr. */ |