Show / Hide Table of Contents

Class BlockPolicy<T>

A default implementation of IBlockPolicy<T> interface.

Inheritance
Object
BlockPolicy<T>
Implements
IBlockPolicy<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 class BlockPolicy<T> : 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 Source

BlockPolicy(IAction, Int32, Int64, Int32, Int32, Int32, Int32, Func<Transaction<T>, BlockChain<T>, Boolean>, IComparer<BlockPerception>)

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 = 1024L, int difficultyBoundDivisor = 128, int maxTransactionsPerBlock = 100, int maxBlockBytes = 102400, int maxGenesisBytes = 1048576, Func<Transaction<T>, BlockChain<T>, bool> doesTransactionFollowPolicy = null, IComparer<BlockPerception> canonicalChainComparer = 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.

IComparer<BlockPerception> canonicalChainComparer

The custom rule to determine which is the canonical chain. If omitted, TotalDifficultyComparer is used by default.

| Improve this Doc View Source

BlockPolicy(IAction, TimeSpan, Int64, Int32, Int32, Int32, Int32, Func<Transaction<T>, BlockChain<T>, Boolean>, IComparer<BlockPerception>)

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, IComparer<BlockPerception> canonicalChainComparer = 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.

IComparer<BlockPerception> canonicalChainComparer

The custom rule to determine which is the canonical chain. If omitted, TotalDifficultyComparer (having OutdateAfter configured to triple of blockInterval) is used by default.

Properties

| Improve this Doc View Source

BlockAction

A block action to execute and be rendered for every block.

Declaration
public IAction BlockAction { get; }
Property Value
Type Description
IAction
| Improve this Doc View Source

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
| Improve this Doc View Source

CanonicalChainComparer

A comparer to determine which branch is the canonical chain (i.e., best chain). The most greater one according to this comparer is considered to be the canon.

Declaration
public IComparer<BlockPerception> CanonicalChainComparer { get; }
Property Value
Type Description
IComparer<BlockPerception>
See Also
IBlockExcerpt
TotalDifficultyComparer
| Improve this Doc View Source

MaxTransactionsPerBlock

The maximum number of Transactions that a Block<T> can accept. This value must not be negative and must be deterministic (i.e., must not change after an object is once instantiated).

Declaration
public int MaxTransactionsPerBlock { get; }
Property Value
Type Description
Int32
Remarks

If the value is less then 1, it's treated as 1.

Methods

| Improve this Doc View Source

DoesTransactionFollowsPolicy(Transaction<T>, BlockChain<T>)

A predicate that determines if the transaction follows the block policy.

Declaration
public virtual bool DoesTransactionFollowsPolicy(Transaction<T> transaction, BlockChain<T> blockChain)
Parameters
Type Name Description
Transaction<T> transaction

A Transaction<T> to determine.

BlockChain<T> blockChain

A BlockChain<T> for given transaction.

Returns
Type Description
Boolean

true if transactionis valid; otherwise, false.

| Improve this Doc View Source

GetMaxBlockBytes(Int64)

Gets the maximum length of a Block<T> in bytes. It can vary depending on a given index, but should be deterministic; for the same index, the same value must be returned.

Declaration
public int GetMaxBlockBytes(long index)
Parameters
Type Name Description
Int64 index

An Index of a block to mine or receive.

Returns
Type Description
Int32

The maximum length of a Block<T> in bytes to accept.

Remarks

If it returns less then 1, it is treated as 1, because there is no block taking 0 bytes or negative length of bytes.

| Improve this Doc View Source

GetNextBlockDifficulty(BlockChain<T>)

Determines a right Difficulty for a new Block<T> to be mined right after the given blocks.

Declaration
public virtual long GetNextBlockDifficulty(BlockChain<T> blocks)
Parameters
Type Name Description
BlockChain<T> blocks

Consecutive Block<T>s to be followed by a new Block<T> to be mined.

Returns
Type Description
Int64

A right Difficulty for a new Block<T> to be mined.

| Improve this Doc View Source

ValidateNextBlock(BlockChain<T>, Block<T>)

Checks if nextBlock is invalid, and if that returns the reason.

Note that it returns null when nextBlock is valid.

Declaration
public virtual InvalidBlockException ValidateNextBlock(BlockChain<T> blocks, Block<T> nextBlock)
Parameters
Type Name Description
BlockChain<T> blocks

Consecutive Block<T>s to append nextBlock.

Block<T> nextBlock

The next block to append to blocks.

Returns
Type Description
InvalidBlockException

The reason why the given blocks are invalid, or null if blocks are valid.

Implements

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