Show / Hide Table of Contents

Interface IBlockPolicy<T>

An interface to determine if consecutive Block<T>s are valid.

An implementation of this interface should perform all policy dependent checks, such as whether a Block<T> has the right difficulty, a Transaction<T> has the right signer, etc.

Namespace: Libplanet.Blockchain.Policies
Assembly: Libplanet.dll
Syntax
public interface IBlockPolicy<T>
    where T : IAction, new()
Type Parameters
Name Description
T

An IAction type. It should match Block<T>'s type parameter.

Properties

| Improve this Doc View Source

BlockAction

An IAction to execute and be rendered for every block, if any.

Declaration
IAction BlockAction { get; }
Property Value
Type Description
IAction
| 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
IComparer<IBlockExcerpt> CanonicalChainComparer { get; }
Property Value
Type Description
IComparer<IBlockExcerpt>
See Also
IBlockExcerpt
TotalDifficultyComparer

Methods

| Improve this Doc View Source

GetHashAlgorithm(Int64)

Gets the HashAlgorithmType to use for block's proof-of-work.

Declaration
HashAlgorithmType GetHashAlgorithm(long index)
Parameters
Type Name Description
Int64 index

The Index of the Block<T> to do proof-of-work.

Returns
Type Description
HashAlgorithmType

The HashAlgorithmType to use.

| Improve this Doc View Source

GetMaxBlockBytes(Int64)

Gets the maximum length of a Block<T> in bytes.

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

The Index of the Block<T> for which this constraint should apply.

Returns
Type Description
Int32

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

| Improve this Doc View Source

GetMaxTransactionsPerBlock(Int64)

Gets the maximum number of Transaction<T>s allowed for a valid Block<T>.

Declaration
int GetMaxTransactionsPerBlock(long index)
Parameters
Type Name Description
Int64 index

The Index of the Block<T> for which this constraint should apply.

Returns
Type Description
Int32

The maximum number of Transaction<T>s allowed for a valid Block<T> can accept.

| Improve this Doc View Source

GetMaxTransactionsPerSignerPerBlock(Int64)

Gets the maximum number of Transaction<T>s allowed per signer for a valid Block<T>.

Declaration
int GetMaxTransactionsPerSignerPerBlock(long index)
Parameters
Type Name Description
Int64 index

The Index of the Block<T> for which this constraint should apply.

Returns
Type Description
Int32

The maximum number of Transaction<T>s allowed per signer for a valid Block<T> can accept.

| Improve this Doc View Source

GetMinTransactionsPerBlock(Int64)

Gets the minimum number of Transaction<T>s allowed for a valid Block<T>.

Declaration
int GetMinTransactionsPerBlock(long index)
Parameters
Type Name Description
Int64 index

The Index of the Block<T> for which this constraint should apply.

Returns
Type Description
Int32

The minimum number of Transaction<T>s allowed for a valid Block<T> can accept.

| Improve this Doc View Source

GetNextBlockDifficulty(BlockChain<T>)

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

Declaration
long GetNextBlockDifficulty(BlockChain<T> blockChain)
Parameters
Type Name Description
BlockChain<T> blockChain

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 a Block<T> can be appended to the given BlockChain<T>.

Declaration
BlockPolicyViolationException ValidateNextBlock(BlockChain<T> blockChain, Block<T> nextBlock)
Parameters
Type Name Description
BlockChain<T> blockChain

The target BlockChain<T> to append nextBlock.

Block<T> nextBlock

The next block to append to blockChain.

Returns
Type Description
BlockPolicyViolationException

A BlockPolicyViolationException with a description as to why given nextBlock is invalid, or null if nextBlock is valid.

Remarks

Note that ValidateNextBlockTx(BlockChain<T>, Transaction<T>) will be called separately from a BlockChain<T> when appending a Block<T>. Hence, to reduce redundancy, an implementation of this interface should not call ValidateNextBlockTx(BlockChain<T>, Transaction<T>).

| Improve this Doc View Source

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

Checks if a Transaction<T> can be included in a yet to be mined Block<T> that can be appended to the given BlockChain<T>.

Declaration
TxPolicyViolationException ValidateNextBlockTx(BlockChain<T> blockChain, Transaction<T> transaction)
Parameters
Type Name Description
BlockChain<T> blockChain

The target BlockChain<T> to include given transaction.

Transaction<T> transaction

The Transaction<T> to consider.

Returns
Type Description
TxPolicyViolationException

A TxPolicyViolationException with a description as to why given transaction is invalid, or null if transaction is valid.

Remarks

This is used in two different cases:

  • When selecting which Transaction<T> to include when mining a next Block<T>.
  • When appending a Block<T> with transaction to a BlockChain<T>.
This is called separately from ValidateNextBlock(BlockChain<T>, Block<T>) from a BlockChain<T>.
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium