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) 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 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(IConsensusMessageCommunicator, BlockChain, Int64, PrivateKey, ValidatorSet, ContextTimeoutOption)
Initializes a new instance of the Context class.
Declaration
public Context(IConsensusMessageCommunicator consensusMessageCommunicator, BlockChain blockChain, long height, PrivateKey privateKey, ValidatorSet validators, ContextTimeoutOption contextTimeoutOptions)
Parameters
Type | Name | Description |
---|---|---|
IConsensusMessageCommunicator | consensusMessageCommunicator | A communicator for receiving ConsensusMsg from or publishing 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,Libplanet.Types.Blocks.BlockHash,Libplanet.Types.Consensus.VoteFlag) |
ValidatorSet | validators | The ValidatorSet for
given |
ContextTimeoutOption | contextTimeoutOptions | A ContextTimeoutOption for configuring a timeout for each ConsensusStep. |
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.
Proposal
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) 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 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 Proposal Proposal { get; }
Property Value
Type | Description |
---|---|
Proposal |
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 ConsensusStep Step { get; }
Property Value
Type | Description |
---|---|
ConsensusStep |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Methods
| Improve this Doc View SourceAddMaj23(Maj23)
Add a ConsensusMsg to the context.
Declaration
public VoteSetBits AddMaj23(Maj23 maj23)
Parameters
Type | Name | Description |
---|---|---|
Maj23 | maj23 | A ConsensusMsg to add. |
Returns
Type | Description |
---|---|
VoteSetBits | A VoteSetBits if given |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Dispose()
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) 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 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.
GetVoteSetBits(Int32, BlockHash, VoteFlag)
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) 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 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 VoteSetBits GetVoteSetBits(int round, BlockHash blockHash, VoteFlag flag)
Parameters
Type | Name | Description |
---|---|---|
Int32 | round | |
BlockHash | blockHash | |
VoteFlag | flag |
Returns
Type | Description |
---|---|
VoteSetBits |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
GetVoteSetBitsResponse(VoteSetBits)
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) 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 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 IEnumerable<ConsensusMsg> GetVoteSetBitsResponse(VoteSetBits voteSetBits)
Parameters
Type | Name | Description |
---|---|---|
VoteSetBits | voteSetBits |
Returns
Type | Description |
---|---|
IEnumerable<ConsensusMsg> |
Remarks
A Context represents a consensus of a single height and its multiple rounds.
Start(BlockCommit)
Starts round #0 of consensus for Height.
Declaration
public void Start(BlockCommit lastCommit = null)
Parameters
Type | Name | Description |
---|---|---|
BlockCommit | lastCommit | A LastCommit from previous block. |
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.