Class BlockPolicy
A default implementation of IBlock
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 Block
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<Time |
blockInterval | Goes to Block |
Func<Block |
validateNextBlockTx | The predicate that determines if a Transaction follows the policy. Set to a constant function of null by default. |
Func<Block |
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 Get |
Func<Int64, Int32> | getMaxTransactionsPerBlock | The function determining how many
Transactions can be included in a Block.
Goes to Get |
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 Get |
Fields
| Improve this Doc View SourceDefaultTargetBlockInterval
A default implementation of IBlock
Declaration
public static readonly TimeSpan DefaultTargetBlockInterval
Field Value
Type | Description |
---|---|
Time |
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 |
---|---|
Time |
Methods
| Improve this Doc View SourceGetMaxTransactionsBytes(Int64)
Gets the maximum length of Transactions in bytes.
Declaration
[Pure]
public long GetMaxTransactionsBytes(long index)
Parameters
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
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
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
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 Block
Declaration
public virtual BlockPolicyViolationException ValidateNextBlock(BlockChain blockChain, Block nextBlock)
Parameters
Type | Name | Description |
---|---|---|
Block |
blockChain | The target Block |
Block | nextBlock | The next block to append to
|
Returns
Type | Description |
---|---|
Block |
A Block |
Remarks
Note that Validate
ValidateNextBlockTx(BlockChain, Transaction)
Checks if a Transaction can be included in a yet to be mined
Block that can be appended to the given Block
Declaration
public virtual TxPolicyViolationException ValidateNextBlockTx(BlockChain blockChain, Transaction transaction)
Parameters
Type | Name | Description |
---|---|---|
Block |
blockChain | The target Block |
Transaction | transaction | The Transaction to consider. |
Returns
Type | Description |
---|---|
Tx |
A Tx |
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 .