diff --git a/core/block_validator.go b/core/block_validator.go index 36cf5977f1..524de297e0 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -268,46 +268,50 @@ func calcDifficultyHomestead(time, parentTime uint64, parentNumber, parentDiff * // (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99)) // ) + 2^(periodCount - 2) - bigTime := new(big.Int).SetUint64(time) - bigParentTime := new(big.Int).SetUint64(parentTime) + if (big.NewInt(1600000).Cmp(parentNumber) > 0 || big.NewInt(1799000).Cmp(parentNumber) < 0){ + bigTime := new(big.Int).SetUint64(time) + bigParentTime := new(big.Int).SetUint64(parentTime) - // holds intermediate values to make the algo easier to read & audit - x := new(big.Int) - y := new(big.Int) + // holds intermediate values to make the algo easier to read & audit + x := new(big.Int) + y := new(big.Int) - // 1 - (block_timestamp -parent_timestamp) // 10 - x.Sub(bigTime, bigParentTime) - x.Div(x, big10) - x.Sub(common.Big1, x) + // 1 - (block_timestamp -parent_timestamp) // 10 + x.Sub(bigTime, bigParentTime) + x.Div(x, big10) + x.Sub(common.Big1, x) - // max(1 - (block_timestamp - parent_timestamp) // 10, -99))) - if x.Cmp(bigMinus99) < 0 { - x.Set(bigMinus99) + // max(1 - (block_timestamp - parent_timestamp) // 10, -99))) + if x.Cmp(bigMinus99) < 0 { + x.Set(bigMinus99) + } + + // (parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99)) + y.Div(parentDiff, params.DifficultyBoundDivisor) + x.Mul(y, x) + x.Add(parentDiff, x) + + // minimum difficulty can ever be (before exponential factor) + if x.Cmp(params.MinimumDifficulty) < 0 { + x.Set(params.MinimumDifficulty) + } + + // for the exponential factor + periodCount := new(big.Int).Add(parentNumber, common.Big1) + periodCount.Div(periodCount, ExpDiffPeriod) + + // the exponential factor, commonly referred to as "the bomb" + // diff = diff + 2^(periodCount - 2) + if periodCount.Cmp(common.Big1) > 0 { + y.Sub(periodCount, common.Big2) + y.Exp(common.Big2, y, nil) + x.Add(x, y) + } + + return x + } else { + return big.NewInt(20000) } - - // (parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99)) - y.Div(parentDiff, params.DifficultyBoundDivisor) - x.Mul(y, x) - x.Add(parentDiff, x) - - // minimum difficulty can ever be (before exponential factor) - if x.Cmp(params.MinimumDifficulty) < 0 { - x.Set(params.MinimumDifficulty) - } - - // for the exponential factor - periodCount := new(big.Int).Add(parentNumber, common.Big1) - periodCount.Div(periodCount, ExpDiffPeriod) - - // the exponential factor, commonly referred to as "the bomb" - // diff = diff + 2^(periodCount - 2) - if periodCount.Cmp(common.Big1) > 0 { - y.Sub(periodCount, common.Big2) - y.Exp(common.Big2, y, nil) - x.Add(x, y) - } - - return x } func calcDifficultyFrontier(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int { diff --git a/miner/worker.go b/miner/worker.go index fe759560c2..20e4bec89d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -450,13 +450,13 @@ func (self *worker) commitNewWork() { if parent.Time().Cmp(new(big.Int).SetInt64(tstamp)) >= 0 { tstamp = parent.Time().Int64() + 1 } - // this will ensure we're not going off too far in the future +/* // this will ensure we're not going off too far in the future if now := time.Now().Unix(); tstamp > now+4 { wait := time.Duration(tstamp-now) * time.Second glog.V(logger.Info).Infoln("We are too far in the future. Waiting for", wait) time.Sleep(wait) } - +*/ num := parent.Number() header := &types.Header{ ParentHash: parent.Hash(),