mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
consensus/ubqhash: Check we have enough blocks (supprt custom ubqhash net with flux activating before block 88)
This commit is contained in:
parent
fbc1784ff7
commit
213a9fe947
1 changed files with 7 additions and 2 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue