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's type parameter.

Constructors

| Improve this Doc View Source

BlockPolicy(IAction, Nullable<TimeSpan>, Func<BlockChain<T>, Transaction, TxPolicyViolationException>, Func<BlockChain<T>, Block, BlockPolicyViolationException>, Func<Int64, Int64>, Func<Int64, Int32>, Func<Int64, Int32>, Func<Int64, Int32>)

Creates a default BlockPolicy<T> instance.

Each unprovided argument will be assigned a default value. See each parameter description for more detail.

Declaration
public BlockPolicy(IAction blockAction = null, TimeSpan? blockInterval = null, Func<BlockChain<T>, Transaction, TxPolicyViolationException> validateNextBlockTx = null, Func<BlockChain<T>, Block, BlockPolicyViolationException> validateNextBlock = null, Func<long, long> getMaxTransactionsBytes = null, Func<long, int> getMinTransactionsPerBlock = null, Func<long, int> getMaxTransactionsPerBlock = null, Func<long, int> getMaxTransactionsPerSignerPerBlock = null)
Parameters
Type Name Description
IAction blockAction

A IAction to executed for every Block. Set to null by default, which results in no additional execution other than those included in Transactions.

Nullable<TimeSpan> blockInterval

Goes to BlockInterval. Set to DefaultTargetBlockInterval by default.

Func<BlockChain<T>, Transaction, TxPolicyViolationException> validateNextBlockTx

The predicate that determines if a Transaction follows the policy. Set to a constant function of null by default.

Func<BlockChain<T>, Block, BlockPolicyViolationException> validateNextBlock

The predicate that determines if a Block follows the policy. Set to a default implementation where block's hash algorithm type, bytes count, and transactions count are validated.

Func<Int64, Int64> getMaxTransactionsBytes

The function determining the maximum size of Transactions in number of bytes given its Index. Goes to GetMaxTransactionsBytes(Int64). Set to a constant size of 100KiB, i.e. 100 * 1024, by default.

Func<Int64, Int32> getMinTransactionsPerBlock

The function determining the minimum number of Transactions that must be included in a Block. Goes to GetMinTransactionsPerBlock(Int64). Set to a constant function of 0 by default.

Func<Int64, Int32> getMaxTransactionsPerBlock

The function determining how many Transactions can be included in a Block. Goes to GetMaxTransactionsPerBlock(Int64). Set to a constant function of 100 by default.

Func<Int64, Int32> getMaxTransactionsPerSignerPerBlock

The function determining the maximum number of transactions from the same signer that can be included in a Block given the Block's index. Goes to GetMaxTransactionsPerSignerPerBlock(Int64). Set to GetMaxTransactionsPerBlock(Int64) by default.

Fields

| Improve this Doc View Source

DefaultTargetBlockInterval

A default implementation of IBlockPolicy<T> interface.

Declaration
public static readonly TimeSpan DefaultTargetBlockInterval
Field Value
Type Description
TimeSpan

Properties

| Improve this Doc View Source

BlockAction

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

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

BlockInterval

Targeted time interval between two consecutive Blocks.

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

FeeCalculator

A default implementation of IBlockPolicy<T> interface.

Declaration
public IFeeCalculator FeeCalculator { get; }
Property Value
Type Description
IFeeCalculator

Methods

| Improve this Doc View Source

GetMaxTransactionsBytes(Int64)

Gets the maximum length of Transactions in bytes.

Declaration
[Pure]
public long GetMaxTransactionsBytes(long index)
Parameters
Type Name Description
Int64 index

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

Returns
Type Description
Int64

The maximum length of Transactions in bytes to accept.

| Improve this Doc View Source

GetMaxTransactionsPerBlock(Int64)

Gets the maximum number of Transactions allowed for a valid Block.

Declaration
[Pure]
public int GetMaxTransactionsPerBlock(long index)
Parameters
Type Name Description
Int64 index

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

Returns
Type Description
Int32

The maximum number of Transactions allowed for a valid Block can accept.

| Improve this Doc View Source

GetMaxTransactionsPerSignerPerBlock(Int64)

Gets the maximum number of Transactions allowed per signer for a valid Block.

Declaration
[Pure]
public int GetMaxTransactionsPerSignerPerBlock(long index)
Parameters
Type Name Description
Int64 index

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

Returns
Type Description
Int32

The maximum number of Transactions allowed per signer for a valid Block can accept.

| Improve this Doc View Source

GetMinTransactionsPerBlock(Int64)

Gets the minimum number of Transactions allowed for a valid Block.

Declaration
[Pure]
public int GetMinTransactionsPerBlock(long index)
Parameters
Type Name Description
Int64 index

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

Returns
Type Description
Int32

The minimum number of Transactions allowed for a valid Block can accept.

| Improve this Doc View Source

ValidateNextBlock(BlockChain<T>, Block)

Checks if a Block can be appended to the given BlockChain<T>.

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

The target BlockChain<T> to append nextBlock.

Block 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) will be called separately from a BlockChain<T> when appending a Block. Hence, to reduce redundancy, an implementation of this interface should not call ValidateNextBlockTx(BlockChain<T>, Transaction).

| Improve this Doc View Source

ValidateNextBlockTx(BlockChain<T>, Transaction)

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

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

The target BlockChain<T> to include given transaction.

Transaction transaction

The Transaction 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 to include when mining a next Block.
  • When appending a Block with transaction to a BlockChain<T>.
This is called separately from ValidateNextBlock(BlockChain<T>, Block) from a BlockChain<T>.

Implements

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