func (cs *ConsensusSet) getBlockTotals(tx *bolt.Tx, id types.BlockID) (totalTime int64, totalTarget types.Target) {
	totalsBytes := tx.Bucket(BucketOak).Get(id[:])
	totalTime = int64(binary.LittleEndian.Uint64(totalsBytes[:8]))
	copy(totalTarget[:], totalsBytes[8:])
	return
}
getBlockTotals returns the block totals values that get stored in
storeBlockTotals.
package consensus
import (
	"bytes"
	"encoding/binary"
	"math/big"
	"github.com/NebulousLabs/Sia/types"
	"github.com/NebulousLabs/errors"
	"github.com/coreos/bbolt"
)
var (
	errOakHardforkIncompatibility = errors.New("difficulty adjustment hardfork incompatibility detected")
)
func (cs *ConsensusSet) childTargetOak(parentTotalTime int64, parentTotalTarget, currentTarget types.Target, parentHeight types.BlockHeight, parentTimestamp types.Timestamp) types.Target {
	var delta int64
	if parentHeight < types.OakHardforkFixBlock {
		expectedTime := int64(types.BlockFrequency * parentHeight)
		delta = expectedTime - parentTotalTime
	} else {
		expectedTime := int64(types.BlockFrequency*parentHeight) + int64(types.GenesisTimestamp)
		delta = expectedTime - int64(parentTimestamp)
	}
	square := delta * delta
	if delta < 0 {
		square *= -1
	}
	shift := square / 10e6  
	targetBlockTime := int64(types.BlockFrequency) + shift
	if targetBlockTime < int64(types.BlockFrequency)/types.OakMaxBlockShift {
		targetBlockTime = int64(types.BlockFrequency) / types.OakMaxBlockShift
	}
	if targetBlockTime > int64(types.BlockFrequency)*types.OakMaxBlockShift {
		targetBlockTime = int64(types.BlockFrequency) * types.OakMaxBlockShift
	}
	if parentTotalTime < 1 {
		parentTotalTime = 1
	}
	visibleHashrate := parentTotalTarget.Difficulty().Div64(uint64(parentTotalTime))  
	if visibleHashrate.IsZero() {
		visibleHashrate = visibleHashrate.Add(types.NewCurrency64(1))
	}
	if targetBlockTime == 0 {
		targetBlockTime = 1
	}
	maxNewTarget := currentTarget.MulDifficulty(types.OakMaxRise)  
	minNewTarget := currentTarget.MulDifficulty(types.OakMaxDrop)  
	newTarget := types.RatToTarget(new(big.Rat).SetFrac(types.RootDepth.Int(), visibleHashrate.Mul64(uint64(targetBlockTime)).Big()))
	if newTarget.Cmp(maxNewTarget) < 0 {
		newTarget = maxNewTarget
	}
	if newTarget.Cmp(minNewTarget) > 0 {
		newTarget = minNewTarget
	}
	return newTarget
}