aboutsummaryrefslogtreecommitdiff
path: root/src/pow.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-03-17 06:35:59 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2015-04-22 03:53:25 -0700
commitf7303f97933be33e34d482cf8348d180c8da2a26 (patch)
tree5612e3678a19c1412212ca034e7c7a8b959aa9f1 /src/pow.cpp
parentb6ea3bcede1cbbf89486b9d67329e0110c4624ae (diff)
Use equivalent PoW for non-main-chain requests
Diffstat (limited to 'src/pow.cpp')
-rw-r--r--src/pow.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/pow.cpp b/src/pow.cpp
index fc6ed4f3d1..bb53ad204b 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -114,3 +114,20 @@ arith_uint256 GetBlockProof(const CBlockIndex& block)
// or ~bnTarget / (nTarget+1) + 1.
return (~bnTarget / (bnTarget + 1)) + 1;
}
+
+int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params)
+{
+ arith_uint256 r;
+ int sign = 1;
+ if (to.nChainWork > from.nChainWork) {
+ r = to.nChainWork - from.nChainWork;
+ } else {
+ r = from.nChainWork - to.nChainWork;
+ sign = -1;
+ }
+ r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip);
+ if (r.bits() > 63) {
+ return sign * std::numeric_limits<int64_t>::max();
+ }
+ return sign * r.GetLow64();
+}