Class BlockPolicy
A default implementation of IBlockPolicy interface.
Implements
Inherited Members
Namespace: Libplanet.Blockchain.Policies
Assembly: Libplanet.dll
Syntax
public class BlockPolicy : IBlockPolicy
Constructors
| Improve this Doc View SourceBlockPolicy(IAction, Nullable<TimeSpan>, Func<BlockChain, Transaction, TxPolicyViolationException>, Func<BlockChain, Block, BlockPolicyViolationException>, Func<Int64, Int64>, Func<Int64, Int32>, Func<Int64, Int32>, Func<Int64, Int32>)
Creates a default BlockPolicy 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, Transaction, TxPolicyViolationException> validateNextBlockTx = null, Func<BlockChain, 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, Transaction, TxPolicyViolationException> | validateNextBlockTx | The predicate that determines if a Transaction follows the policy. Set to a constant function of null by default. |
Func<BlockChain, 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 |
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 |
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 |
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 SourceDefaultTargetBlockInterval
A default implementation of IBlockPolicy interface.
Declaration
public static readonly TimeSpan DefaultTargetBlockInterval
Field Value
Type | Description |
---|---|
TimeSpan |
Properties
| Improve this Doc View SourceBlockAction
An IAction to execute and be rendered for every block, if any.
Declaration
public IAction BlockAction { get; }
Property Value
Type | Description |
---|---|
IAction |
BlockInterval
Targeted time interval between two consecutive Blocks.
Declaration
public TimeSpan BlockInterval { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
FeeCalculator
A default implementation of IBlockPolicy interface.
Declaration
public IFeeCalculator FeeCalculator { get; }
Property Value
Type | Description |
---|---|
IFeeCalculator |
Methods
| Improve this Doc View SourceGetMaxTransactionsBytes(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. |
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. |
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. |
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. |
ValidateNextBlock(BlockChain, Block)
Checks if a Block can be appended to the given BlockChain.
Declaration
public virtual BlockPolicyViolationException ValidateNextBlock(BlockChain blockChain, Block nextBlock)
Parameters
Type | Name | Description |
---|---|---|
BlockChain | blockChain | The target BlockChain to
append |
Block | nextBlock | The next block to append to
|
Returns
Type | Description |
---|---|
BlockPolicyViolationException | A BlockPolicyViolationException with a description
as to why given |
Remarks
Note that ValidateNextBlockTx(BlockChain, Transaction) will be called separately from a BlockChain when appending a Block. Hence, to reduce redundancy, an implementation of this interface should not call ValidateNextBlockTx(BlockChain, Transaction).
ValidateNextBlockTx(BlockChain, Transaction)
Checks if a Transaction can be included in a yet to be mined Block that can be appended to the given BlockChain.
Declaration
public virtual TxPolicyViolationException ValidateNextBlockTx(BlockChain blockChain, Transaction transaction)
Parameters
Type | Name | Description |
---|---|---|
BlockChain | blockChain | The target BlockChain to include
given |
Transaction | transaction | The Transaction to consider. |
Returns
Type | Description |
---|---|
TxPolicyViolationException | A TxPolicyViolationException with a description
as to why given |
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.