Class DifficultyAdjustment<T>
Inherited Members
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 SourceDefaultDifficultyStability
Declaration
public static readonly long DefaultDifficultyStability
Field Value
Type | Description |
---|---|
Int64 |
DefaultMinimumDifficulty
Declaration
public static readonly long DefaultMinimumDifficulty
Field Value
Type | Description |
---|---|
Int64 |
DefaultTargetBlockInterval
Declaration
public static readonly TimeSpan DefaultTargetBlockInterval
Field Value
Type | Description |
---|---|
TimeSpan |
Methods
| Improve this Doc View SourceAlgorithmFactory(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 |
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 |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If any of the arguments fail to satisfy the necessary constraints for the formula to work. |
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 |
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 |
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. |