Show / Hide Table of Contents

Class PreEvaluationBlock<T>

A block candidate without evaluating actions (in its Transactions and a possible BlockAction) and state root hash.

Inheritance
Object
PreEvaluationBlockHeader
PreEvaluationBlock<T>
Implements
IPreEvaluationBlock<T>
IBlockContent<T>
IPreEvaluationBlockHeader
IBlockMetadata
Inherited Members
PreEvaluationBlockHeader.Codec
PreEvaluationBlockHeader.ProtocolVersion
PreEvaluationBlockHeader.Index
PreEvaluationBlockHeader.Timestamp
PreEvaluationBlockHeader.Nonce
PreEvaluationBlockHeader.Miner
PreEvaluationBlockHeader.PublicKey
PreEvaluationBlockHeader.Difficulty
PreEvaluationBlockHeader.TotalDifficulty
PreEvaluationBlockHeader.PreviousHash
PreEvaluationBlockHeader.TxHash
PreEvaluationBlockHeader.HashAlgorithm
PreEvaluationBlockHeader.PreEvaluationHash
PreEvaluationBlockHeader.Metadata
PreEvaluationBlockHeader.MakeCandidateData(HashDigest<SHA256>, Nullable<ImmutableArray<Byte>>)
PreEvaluationBlockHeader.MakeSignature(PrivateKey, HashDigest<SHA256>)
PreEvaluationBlockHeader.VerifySignature(Nullable<ImmutableArray<Byte>>, HashDigest<SHA256>)
PreEvaluationBlockHeader.DeriveBlockHash(HashDigest<SHA256>, Nullable<ImmutableArray<Byte>>)
Namespace: Libplanet.Blocks
Assembly: Libplanet.dll
Syntax
public sealed class PreEvaluationBlock<T> : PreEvaluationBlockHeader, IPreEvaluationBlock<T>, IBlockContent<T>, IPreEvaluationBlockHeader, IBlockMetadata where T : IAction, new()
Type Parameters
Name Description
T

A class implementing IAction to include. This type parameter is aligned with Transaction<T>'s type parameter.

Remarks

It guarantees that every instance of this type has a valid proof-of-work Nonce which satisfies its Difficulty.

Constructors

| Improve this Doc View Source

PreEvaluationBlock(IBlockContent<T>, HashAlgorithmType, Nonce)

Creates a PreEvaluationBlock<T> instance with its content data and a valid proof-of-work nonce which satisfies the required Difficulty.

Declaration
public PreEvaluationBlock(IBlockContent<T> content, HashAlgorithmType hashAlgorithm, Nonce nonce)
Parameters
Type Name Description
IBlockContent<T> content

Block's content data.

HashAlgorithmType hashAlgorithm

The hash algorithm used for calculating PreEvaluationHash.

Nonce nonce

A valid proof-of-work nonce which satisfies the required Difficulty.

Remarks

PreEvaluationHash is automatically derived from the given arguments.

Exceptions
Type Condition
InvalidBlockProtocolVersionException

Thrown when the content's to set is ProtocolVersion is less than 0, or greater than CurrentProtocolVersion, the latest known protocol version.

InvalidBlockIndexException

Thrown when the value to set is negative.

InvalidBlockDifficultyException

Thrown when the value to set is is negative.

InvalidBlockTotalDifficultyException

Thrown when the content's TotalDifficulty is less than its Difficulty.

InvalidTxSignatureException

Thrown when any tx signature is invalid or not signed by its signer.

InvalidTxPublicKeyException

Thrown when any tx signer is not derived from its its public key.

InvalidTxNonceException

Thrown when the same tx nonce is used by a signer twice or more, or a tx nonce is used without its previous nonce by a signer. Note that this validates only a block's intrinsic integrity between its transactions, but does not guarantee integrity between blocks. Such validation needs to be conducted by BlockChain<T>.

InvalidTxGenesisHashException

Thrown when transactions to set have inconsistent genesis hashes.

InvalidBlockTxHashException

Thrown when the given block content's TxHash is not consistent with its Transactions.

InvalidBlockNonceException

Thrown when the given proof-of-work nonce does not satisfy the required Difficulty.

| Improve this Doc View Source

PreEvaluationBlock(IBlockContent<T>, HashAlgorithmType, Nonce, ImmutableArray<Byte>)

Creates a PreEvaluationBlock<T> instance with its content data, a valid proof-of-work nonce which satisfies the required Difficulty, and a preEvaluationHash digest derived from them.

Declaration
public PreEvaluationBlock(IBlockContent<T> content, HashAlgorithmType hashAlgorithm, Nonce nonce, ImmutableArray<byte> preEvaluationHash)
Parameters
Type Name Description
IBlockContent<T> content

Block's content data.

HashAlgorithmType hashAlgorithm

The hash algorithm used for calculating PreEvaluationHash.

Nonce nonce

A valid proof-of-work nonce which satisfies the required Difficulty.

ImmutableArray<Byte> preEvaluationHash

The hash digest of the hashAlgorithm derived from the given arguments.

Exceptions
Type Condition
InvalidBlockProtocolVersionException

Thrown when the content's ProtocolVersion is less than 0, or greater than CurrentProtocolVersion, the latest known protocol version.

InvalidBlockIndexException

Thrown when the value to set is negative.

InvalidBlockDifficultyException

Thrown when the value to set is is negative.

InvalidBlockTotalDifficultyException

Thrown when the content's TotalDifficulty is less than its Difficulty.

InvalidTxSignatureException

Thrown when any tx signature is invalid or not signed by its signer.

InvalidTxPublicKeyException

Thrown when any tx signer is not derived from its its public key.

InvalidTxNonceException

Thrown when the same tx nonce is used by a signer twice or more, or a tx nonce is used without its previous nonce by a signer. Note that this validates only a block's intrinsic integrity between its transactions, but does not guarantee integrity between blocks. Such validation needs to be conducted by BlockChain<T>.

InvalidTxGenesisHashException

Thrown when transactions to set have inconsistent genesis hashes.

InvalidBlockTxHashException

Thrown when the given block content's TxHash is not consistent with its Transactions.

InvalidBlockPreEvaluationHashException

Thrown when the given preEvaluationHash is invalid.

InvalidBlockNonceException

Thrown when the given proof-of-work nonce does not satisfy the required Difficulty.

Properties

| Improve this Doc View Source

Transactions

Transactions belonging to the block.

Declaration
public IReadOnlyList<Transaction<T>> Transactions { get; }
Property Value
Type Description
IReadOnlyList<Transaction<T>>
Remarks

This is always ordered by Id.

Methods

| Improve this Doc View Source

DetermineStateRootHash(IAction, IStateStore)

Evaluates all actions in the Transactions and a blockAction (if any), and determines the StateRootHash from ground zero (i.e., empty state root).

Declaration
public HashDigest<SHA256> DetermineStateRootHash(IAction blockAction, IStateStore stateStore)
Parameters
Type Name Description
IAction blockAction

An optional BlockAction.

IStateStore stateStore

The Libplanet.Blockchain.BlockChain`1.StateStore.

Returns
Type Description
HashDigest<SHA256>

The resulting StateRootHash.

Remarks

This can be used with only genesis blocks. For blocks with indices greater than zero, use DetermineStateRootHash(BlockChain<T>) overloaded one instead.

| Improve this Doc View Source

DetermineStateRootHash(BlockChain<T>)

Evaluates all actions in the Transactions and an optional BlockAction, and determines the StateRootHash.

Declaration
public HashDigest<SHA256> DetermineStateRootHash(BlockChain<T> blockChain)
Parameters
Type Name Description
BlockChain<T> blockChain

The blockchain on which actions are evaluated based.

Returns
Type Description
HashDigest<SHA256>

The resulting StateRootHash.

| Improve this Doc View Source

Evaluate(PrivateKey, IAction, IStateStore)

Evaluates all actions in the Transactions and a blockAction (if any), and returns a Block<T> instance combined with the StateRootHash determined from ground zero (i.e., empty state root). The returned Block<T> is signed by the given privateKey.

Declaration
public Block<T> Evaluate(PrivateKey privateKey, IAction blockAction, IStateStore stateStore)
Parameters
Type Name Description
PrivateKey privateKey

The miner's private key to be used for signing the block. This must match to the block's Miner and PublicKey.

IAction blockAction

An optional BlockAction.

IStateStore stateStore

The Libplanet.Blockchain.BlockChain`1.StateStore.

Returns
Type Description
Block<T>

The block combined with the resulting StateRootHash. It is signed by the given privateKey.

Remarks

This can be used with only genesis blocks. For blocks with indices greater than zero, use DetermineStateRootHash(BlockChain<T>) overloaded one instead.

| Improve this Doc View Source

Evaluate(PrivateKey, BlockChain<T>)

Evaluates all actions in the Transactions and an optional BlockAction, and returns a Block<T> instance combined with the StateRootHash determined from ground zero (i.e., empty state root). The returned Block<T> is signed by the given privateKey.

Declaration
public Block<T> Evaluate(PrivateKey privateKey, BlockChain<T> blockChain)
Parameters
Type Name Description
PrivateKey privateKey

The miner's private key to be used for signing the block. This must match to the block's Miner and PublicKey.

BlockChain<T> blockChain

The blockchain on which actions are evaluated based.

Returns
Type Description
Block<T>

The block combined with the resulting StateRootHash. It is signed by the given privateKey.

Remarks

As blocks have their signatures since the ProtocolVersion 2, it is not usable with blocks of the earlier ProtocolVersions than 2. To create a Block<T> instance with ProtocolVersion less than 2, use Block<T>'s constructors with null signatures.

| Improve this Doc View Source

Sign(PrivateKey, HashDigest<SHA256>)

Signs the block content with the given stateRootHash.

Declaration
public Block<T> Sign(PrivateKey privateKey, HashDigest<SHA256> stateRootHash)
Parameters
Type Name Description
PrivateKey privateKey

The miner's private key to be used for signing the block. This must match to the block's Miner and PublicKey.

HashDigest<SHA256> stateRootHash

The state root hash to include to the input message to sign.

Returns
Type Description
Block<T>

The signed block with the stateRootHash.

Remarks

As blocks have their signatures since the ProtocolVersion 2, it is not usable with blocks of the earlier ProtocolVersions than 2. To create a Block<T> instance with ProtocolVersion less than 2, use Block<T>'s constructors with null signatures.

Implements

IPreEvaluationBlock<T>
IBlockContent<T>
IPreEvaluationBlockHeader
IBlockMetadata
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium