| 133 | } |
| 134 | |
| 135 | int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params) |
| 136 | { |
| 137 | arith_uint256 r; |
| 138 | int sign = 1; |
| 139 | if (to.nChainWork > from.nChainWork) { |
| 140 | r = to.nChainWork - from.nChainWork; |
| 141 | } else { |
| 142 | r = from.nChainWork - to.nChainWork; |
| 143 | sign = -1; |
| 144 | } |
| 145 | r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip); |
| 146 | if (r.bits() > 63) { |
| 147 | return sign * std::numeric_limits<int64_t>::max(); |
| 148 | } |
| 149 | return sign * int64_t(r.GetLow64()); |
| 150 | } |
| 151 | |
| 152 | /** Find the last common ancestor two blocks have. |
| 153 | * Both pa and pb must be non-nullptr. */ |