Show / Hide Table of Contents

Class DifficultyAdjustment<T>

Inheritance
Object
DifficultyAdjustment<T>
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Libplanet.Blockchain.Policies
Assembly: Libplanet.dll
Syntax
public static class DifficultyAdjustment<T>
    where T : IAction, new()
Type Parameters
Name Description
T

Fields

| Improve this Doc View Source

DefaultDifficultyStability

Declaration
public static readonly long DefaultDifficultyStability
Field Value
Type Description
Int64
| Improve this Doc View Source

DefaultMinimumDifficulty

Declaration
public static readonly long DefaultMinimumDifficulty
Field Value
Type Description
Int64
| Improve this Doc View Source

DefaultTargetBlockInterval

Declaration
public static readonly TimeSpan DefaultTargetBlockInterval
Field Value
Type Description
TimeSpan

Methods

| Improve this Doc View Source

AlgorithmFactory(TimeSpan, Int64, Int64)

Does sanity checks and binds arguments to the BaseAlgorithm(BlockChain<T>, TimeSpan, Int64, Int64) based difficulty adjustment algorithm.

Declaration
public static Func<BlockChain<T>, long> AlgorithmFactory(TimeSpan targetBlockInterval, long difficultyStability, long minimumDifficulty)
Parameters
Type Name Description
TimeSpan targetBlockInterval

The base block interval this difficulty adjustment algorithm targets. In reality, the algorithm does not actually target the given TimeSpan. Assuming stable hash rate, the actual average of block intervals comes out to be about targetBaseInterval * 1.4. If ommited, set to DefaultTargetBlockInterval by default.

Int64 difficultyStability

Determines how stable difficulty should be over time. If ommited, set to DefaultDifficultyStability by default.

Int64 minimumDifficulty

The lower bound on the difficulty.

Returns
Type Description
Func<BlockChain<T>, Int64>

The next target difficulty of a Block<T> that gets appended to some . If ommited, set to DefaultMinimumDifficulty by default.

Exceptions
Type Condition
ArgumentOutOfRangeException

If any of the arguments fail to satisfy the necessary constraints for the formula to work.

| Improve this Doc View Source

BaseAlgorithm(BlockChain<T>, TimeSpan, Int64, Int64)

An Ethereum based difficulty adjustment algorithm.

Declaration
public static long BaseAlgorithm(BlockChain<T> blockChain, TimeSpan targetBlockInterval, long difficultystability, long minimumDifficulty)
Parameters
Type Name Description
BlockChain<T> blockChain

The BlockChain<T> instance to calculate the next difficulty from.

TimeSpan targetBlockInterval

The base block interval this difficulty adjustment algorithm targets. In reality, the algorithm does not actually target the given TimeSpan. Assuming stable hash rate, the actual average of block intervals comes out to be about targetBaseInterval * 1.4.

Int64 difficultystability

Determines how stable difficulty should be over time.

Int64 minimumDifficulty

The lower bound on the difficulty. This is ignored for genesis blocks.

Returns
Type Description
Int64

The next target difficulty of a Block<T> that gets appended to blockChain.

Remarks

It is strongly recommended to use the factory version AlgorithmFactory(TimeSpan, Int64, Int64) to get a working difficulty adjustment algorithm.

Exceptions
Type Condition
IndexOutOfRangeException

When the number of blocks in BlockChain<T> is negative.

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium