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