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 |
Properties
| Improve this Doc View SourceBlockAction
An IAction to execute and be rendered for every block, if any.
Declaration
IAction BlockAction { get; }
Property Value
Type | Description |
---|---|
IAction |
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
Methods
| Improve this Doc View SourceGetHashAlgorithm(Int64)
Gets the HashAlgorithmType to use for block's proof-of-work.
Declaration
HashAlgorithmType GetHashAlgorithm(long index)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index |
Returns
Type | Description |
---|---|
HashAlgorithmType | The HashAlgorithmType to use. |
GetMaxBlockBytes(Int64)
Gets the maximum length of a Block<T> in bytes.
Declaration
long GetMaxBlockBytes(long index)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index | The Index of the Block<T> for which this constraint should apply. |
Returns
Type | Description |
---|---|
Int64 | The maximum length of a Block<T> in bytes to accept. |
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. |
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. |
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. |
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. |
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 |
Block<T> | 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<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>).
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<T> | transaction | The Transaction<T> 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<T> to include when mining a next Block<T>.
- When appending a Block<T>
with
transaction
to a BlockChain<T>.