From 213a9fe9470eef34b28d5888d563aa146537c580 Mon Sep 17 00:00:00 2001 From: Luke Williams Date: Sat, 21 Dec 2019 20:19:27 +0100 Subject: [PATCH] consensus/ubqhash: Check we have enough blocks (supprt custom ubqhash net with flux activating before block 88) --- consensus/ubqhash/consensus.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/consensus/ubqhash/consensus.go b/consensus/ubqhash/consensus.go index 3d27815c1f..df24c4288a 100644 --- a/consensus/ubqhash/consensus.go +++ b/consensus/ubqhash/consensus.go @@ -441,14 +441,12 @@ func calcDifficultyDigishieldV3(chain consensus.ChainReader, parentNumber, paren // Limit adjustment step // Use medians to prevent time-warp attacks - // nActualTimespan := nLastBlockTime - nFirstBlockTime nLastBlockTime := chain.CalcPastMedianTime(parentNumber.Uint64(), parent) nFirstBlockTime := chain.CalcPastMedianTime(nFirstBlock.Uint64(), parent) nActualTimespan := new(big.Int) nActualTimespan.Sub(nLastBlockTime, nFirstBlockTime) log.Debug(fmt.Sprintf("CalcDifficulty nActualTimespan = %v before dampening", nActualTimespan)) - // nActualTimespan = AveragingWindowTimespan() + (nActualTimespan-AveragingWindowTimespan())/4 y := new(big.Int) y.Sub(nActualTimespan, averagingWindowTimespan(digishield)) y.Div(y, big.NewInt(4)) @@ -484,6 +482,13 @@ func calcDifficultyFlux(chain consensus.ChainReader, time, parentTime, parentNum nFirstBlock := new(big.Int) nFirstBlock.Sub(parentNumber, fluxConfig.AveragingWindow) + // Check we have enough blocks + if parentNumber.Cmp(fluxConfig.AveragingWindow) < 1 { + log.Debug(fmt.Sprintf("CalcDifficulty: parentNumber(%+x) < fluxConfig.AveragingWindow(%+x)", parentNumber, fluxConfig.AveragingWindow)) + x.Set(parentDiff) + return x + } + diffTime := new(big.Int) diffTime.Sub(time, parentTime)