Class Context
A state machine class of PBFT consensus algorithm. The state machine is responsible for proposing, validating, voting a block and committing the voted block to the blockchain. There are five states:
- Default which is the initial state when the Start(BlockCommit, Boolean) is not called (i.e., round has not been started).
- Propose, which is the state when the round has been started and waiting for the block proposal. If a validator is a proposer of the round, it will propose a block to the other validators and to itself.
- PreVote, which is the state when a block proposal for a round has been received. While translating to this step, state machine votes for the block whether block is valid or not, and waiting for any +2/3 votes from other validators.
- PreCommit, which is the state received any +2/3 votes in PreVote. While translating to this step, state machine votes for whether the block should be committed or not, and waiting for any +2/3 committing votes from other validators. If PreCommit receives +2/3 commit votes with NIL, starts new round Libplanet.Net.Consensus.Context.StartRound(System.Int32) and moves step to Propose.
- EndCommit, which is the state represents committing vote has been received from other validators. Block will be committed to the blockchain and consensus for this height is stopped. (responsibility of next height handling is at Libplanet.Net.Consensus.Context.ConsensusContext).
- In the above states, Propose, If receiving proposal fails in Libplanet.Net.Consensus.Context.TimeoutPropose(System.Int64), then step is moved to PreVote and vote NIL.
- Similar to Propose, PreVote and PreCommit also wait for Libplanet.Net.Consensus.Context.TimeoutPreVote(System.Int64) or Libplanet.Net.Consensus.Context.TimeoutPreCommit(System.Int64) respectively, if +2/3 vote received but neither NIL nor Block is not +2/3. If still +2/3 vote is not received neither NIL nor Block after timeout runs out, then move to next step and vote NIL.
Implements
Inherited Members
Namespace: Libplanet.Net.Consensus
Assembly: Libplanet.Net.dll
Syntax
public class Context : IDisposable
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Constructors
| Improve this Doc View SourceContext(ConsensusContext, BlockChain, Int64, PrivateKey, ValidatorSet, ContextTimeoutOption)
Initializes a new instance of the Context class.
Declaration
public Context(ConsensusContext consensusContext, BlockChain blockChain, long height, PrivateKey privateKey, ValidatorSet validators, ContextTimeoutOption contextTimeoutOptions)
Parameters
Type | Name | Description |
---|---|---|
ConsensusContext | consensusContext | A command class for receiving ConsensusMsg from or broadcasts to other validators. |
BlockChain | blockChain | A blockchain that will be committed, which will be voted by consensus, and used for proposing a block. |
Int64 | height | A target Height of the consensus state. |
PrivateKey | privateKey | A private key for signing a block and message. Libplanet.Net.Consensus.Context.GetValue Libplanet.Net.Consensus.Context.ProcessGenericUponRules Libplanet.Net.Consensus.Context.MakeVote(System.Int32,System.Nullable{Libplanet.Blocks.BlockHash},Libplanet.Consensus.VoteFlag) |
ValidatorSet | validators | The ValidatorSet for
given |
ContextTimeoutOption | contextTimeoutOptions | A ContextTimeoutOption for configuring a timeout for each Step. |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Properties
| Improve this Doc View SourceHeight
A target height of this consensus state. This is also a block index now in consensus.
Declaration
public long Height { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Round
A round represents of this consensus state.
Declaration
public int Round { get; }
Property Value
Type | Description |
---|---|
Int32 |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Step
A step represents of this consensus state. See Context for more detail.
Declaration
public Step Step { get; }
Property Value
Type | Description |
---|---|
Step |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Methods
| Improve this Doc View SourceDispose()
A state machine class of PBFT consensus algorithm. The state machine is responsible for proposing, validating, voting a block and committing the voted block to the blockchain. There are five states:
- Default which is the initial state when the Start(BlockCommit, Boolean) is not called (i.e., round has not been started).
- Propose, which is the state when the round has been started and waiting for the block proposal. If a validator is a proposer of the round, it will propose a block to the other validators and to itself.
- PreVote, which is the state when a block proposal for a round has been received. While translating to this step, state machine votes for the block whether block is valid or not, and waiting for any +2/3 votes from other validators.
- PreCommit, which is the state received any +2/3 votes in PreVote. While translating to this step, state machine votes for whether the block should be committed or not, and waiting for any +2/3 committing votes from other validators. If PreCommit receives +2/3 commit votes with NIL, starts new round Libplanet.Net.Consensus.Context.StartRound(System.Int32) and moves step to Propose.
- EndCommit, which is the state represents committing vote has been received from other validators. Block will be committed to the blockchain and consensus for this height is stopped. (responsibility of next height handling is at Libplanet.Net.Consensus.Context.ConsensusContext).
- In the above states, Propose, If receiving proposal fails in Libplanet.Net.Consensus.Context.TimeoutPropose(System.Int64), then step is moved to PreVote and vote NIL.
- Similar to Propose, PreVote and PreCommit also wait for Libplanet.Net.Consensus.Context.TimeoutPreVote(System.Int64) or Libplanet.Net.Consensus.Context.TimeoutPreCommit(System.Int64) respectively, if +2/3 vote received but neither NIL nor Block is not +2/3. If still +2/3 vote is not received neither NIL nor Block after timeout runs out, then move to next step and vote NIL.
Declaration
public void Dispose()
Remarks
A Context represents a consensus of a single height and its multiple rounds.
GetBlockCommit()
Returns a BlockCommit if the context is committed.
Declaration
public BlockCommit GetBlockCommit()
Returns
Type | Description |
---|---|
BlockCommit | Returns BlockCommit if the context is committed otherwise returns null. |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Start(BlockCommit, Boolean)
Starts round #0 of consensus for Height.
Declaration
public void Start(BlockCommit lastCommit = null, bool bootstrapping = false)
Parameters
Type | Name | Description |
---|---|---|
BlockCommit | lastCommit | A LastCommit from previous block. |
Boolean | bootstrapping | A langword_csharp_bool flag indicating whether this Context should run as a bootstrapping Context or not. |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
ToString()
Returns the summary of context in JSON-formatted string.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | Returns a JSON-formatted string of context state. |
Overrides
Remarks
A Context represents a consensus of a single height and its multiple rounds.