func validNextHeightFromExpected(expectedNextHeight uint64, nextHeight uint64) error {
	if nextHeight < expectedNextHeight-1 || nextHeight > expectedNextHeight {
		return fault.HeightOutOfSequence
	}
	return nil
}
most time next height is increased by 1 from current height,
but it is also valid when incoming block is same height with smaller digest
package blockrecord
import (
	"github.com/bitmark-inc/bitmarkd/blockdigest"
	"github.com/bitmark-inc/bitmarkd/chain"
	"github.com/bitmark-inc/bitmarkd/difficulty"
	"github.com/bitmark-inc/bitmarkd/fault"
)
const (
	blockTimeSpacingInitialInSecond = 240 * 60
	blockTimeSpacingCurrentInSecond = 10 * 60
	initialVersion             = 1
	modifiedTimeSpacingVersion = 2
	difficultyAppliedVersion   = 5
)
func ValidBlockTimeSpacingAtVersion(version uint16, timeSpacing uint64) error {
	if version == initialVersion && timeSpacing > blockTimeSpacingInitialInSecond {
		return fault.InvalidBlockHeaderTimestamp
	}
	if version >= modifiedTimeSpacingVersion && timeSpacing > blockTimeSpacingCurrentInSecond {
		return fault.InvalidBlockHeaderTimestamp
	}
	return nil
}
func ValidIncomingDifficulty(header *Header, chainName string) error {
	if !IsDifficultyAppliedVersion(header.Version) {
		return nil
	}
	if chainName == chain.Local {
		return nil
	}
	if header.Difficulty.Value() != difficulty.Current.Value() {
		return fault.DifficultyDoesNotMatchCalculated
	}
	return nil
}
func IsDifficultyAppliedVersion(version uint16) bool {
	return version >= difficultyAppliedVersion
}
func IsBlockToAdjustDifficulty(height uint64, version uint16) bool {
	if !IsDifficultyAppliedVersion(version) {
		return false
	}
	return isDifficultyAdjustmentBlock(height)
}
func isDifficultyAdjustmentBlock(height uint64) bool {
	return 0 == height%difficulty.AdjustTimespanInBlocks
}
func ValidHeaderVersion(currentVersion uint16, incomingVersion uint16) error {
	if incomingVersion < initialVersion {
		return fault.InvalidBlockHeaderVersion
	}
	if currentVersion > incomingVersion {
		return fault.BlockVersionMustNotDecrease
	}
	return nil
}
func ValidBlockLinkage(currentDigest blockdigest.Digest, incomingDigestOfPreviousBlock blockdigest.Digest) error {
	if currentDigest != incomingDigestOfPreviousBlock {
		return fault.PreviousBlockDigestDoesNotMatch
	}
	return nil
}