Class BlockPolicy<T>
A default implementation of IBlockPolicy<T> interface.
Implements
Namespace: Libplanet.Blockchain.Policies
Assembly: Libplanet.dll
Syntax
public class BlockPolicy<T> : object, IBlockPolicy<T> where T : IAction, new()
Type Parameters
Name | Description |
---|---|
T | An IAction type. It should match to Block<T>'s type parameter. |
Constructors
| Improve this Doc View SourceBlockPolicy(IAction, Int32, Int64, Int32, Int32, Int32, Int32, Func<Transaction<T>, BlockChain<T>, Boolean>)
Creates a BlockPolicy<T> with configuring BlockInterval in milliseconds, Libplanet.Blockchain.Policies.BlockPolicy`1.MinimumDifficulty and Libplanet.Blockchain.Policies.BlockPolicy`1.DifficultyBoundDivisor.
Declaration
public BlockPolicy(IAction blockAction = null, int blockIntervalMilliseconds = 5000, long minimumDifficulty = null, int difficultyBoundDivisor = 128, int maxTransactionsPerBlock = 100, int maxBlockBytes = null, int maxGenesisBytes = null, Func<Transaction<T>, BlockChain<T>, bool> doesTransactionFollowPolicy = null)
Parameters
Type | Name | Description |
---|---|---|
IAction | blockAction | A block action to execute and be rendered for every block. |
Int32 | blockIntervalMilliseconds | Configures BlockInterval in milliseconds. 5000 milliseconds by default. |
Int64 | minimumDifficulty | Configures Libplanet.Blockchain.Policies.BlockPolicy`1.MinimumDifficulty. 1024 by default. |
Int32 | difficultyBoundDivisor | Configures Libplanet.Blockchain.Policies.BlockPolicy`1.DifficultyBoundDivisor. 128 by default. |
Int32 | maxTransactionsPerBlock | Configures MaxTransactionsPerBlock. 100 by default. |
Int32 | maxBlockBytes | Configures GetMaxBlockBytes(Int64) where the block is not a genesis. 100 KiB by default. |
Int32 | maxGenesisBytes | Configures GetMaxBlockBytes(Int64) where the block is a genesis. 1 MiB by default. |
Func<Transaction<T>, BlockChain<T>, Boolean> | doesTransactionFollowPolicy | A predicate that determines if the transaction follows the block policy. |
BlockPolicy(IAction, TimeSpan, Int64, Int32, Int32, Int32, Int32, Func<Transaction<T>, BlockChain<T>, Boolean>)
Creates a BlockPolicy<T> with configuring BlockInterval, Libplanet.Blockchain.Policies.BlockPolicy`1.MinimumDifficulty and Libplanet.Blockchain.Policies.BlockPolicy`1.DifficultyBoundDivisor.
Declaration
public BlockPolicy(IAction blockAction, TimeSpan blockInterval, long minimumDifficulty, int difficultyBoundDivisor, int maxTransactionsPerBlock, int maxBlockBytes, int maxGenesisBytes, Func<Transaction<T>, BlockChain<T>, bool> doesTransactionFollowPolicy = null)
Parameters
Type | Name | Description |
---|---|---|
IAction | blockAction | A block action to execute and be rendered for every block. |
TimeSpan | blockInterval | Configures BlockInterval. |
Int64 | minimumDifficulty | Configures Libplanet.Blockchain.Policies.BlockPolicy`1.MinimumDifficulty. |
Int32 | difficultyBoundDivisor | Configures Libplanet.Blockchain.Policies.BlockPolicy`1.DifficultyBoundDivisor. |
Int32 | maxTransactionsPerBlock | Configures MaxTransactionsPerBlock. |
Int32 | maxBlockBytes | Configures GetMaxBlockBytes(Int64) where the block is not a genesis. |
Int32 | maxGenesisBytes | Configures GetMaxBlockBytes(Int64) where the block is a genesis. |
Func<Transaction<T>, BlockChain<T>, Boolean> | doesTransactionFollowPolicy | A predicate that determines if the transaction follows the block policy. |
Properties
| Improve this Doc View SourceBlockAction
Declaration
public IAction BlockAction { get; }
Property Value
Type | Description |
---|---|
IAction |
BlockInterval
An appropriate interval between consecutive Block<T>s. It is usually from 20 to 30 seconds.
If a previous interval took longer than this GetNextBlockDifficulty(BlockChain<T>) method raises the Difficulty. If it took shorter than this Difficulty is dropped.
Declaration
public TimeSpan BlockInterval { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
MaxTransactionsPerBlock
Declaration
public int MaxTransactionsPerBlock { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceDoesTransactionFollowsPolicy(Transaction<T>, BlockChain<T>)
Declaration
public virtual bool DoesTransactionFollowsPolicy(Transaction<T> transaction, BlockChain<T> blockChain)
Parameters
Type | Name | Description |
---|---|---|
Transaction<T> | transaction | |
BlockChain<T> | blockChain |
Returns
Type | Description |
---|---|
Boolean |
GetMaxBlockBytes(Int64)
Declaration
public int GetMaxBlockBytes(long index)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index |
Returns
Type | Description |
---|---|
Int32 |
GetNextBlockDifficulty(BlockChain<T>)
Declaration
public virtual long GetNextBlockDifficulty(BlockChain<T> blocks)
Parameters
Type | Name | Description |
---|---|---|
BlockChain<T> | blocks |
Returns
Type | Description |
---|---|
Int64 |
ValidateNextBlock(BlockChain<T>, Block<T>)
Declaration
public virtual InvalidBlockException ValidateNextBlock(BlockChain<T> blocks, Block<T> nextBlock)
Parameters
Type | Name | Description |
---|---|---|
BlockChain<T> | blocks | |
Block<T> | nextBlock |
Returns
Type | Description |
---|---|
InvalidBlockException |
Exceptions
Type | Condition |
---|---|
InvalidBlockStateRootHashException | It will be thrown when the given block has incorrect StateRootHash. |