Class ConsensusContext
A class that maintains the states of a Context for block indices now in consensus.
Implements
Inherited Members
Namespace: Libplanet.Net.Consensus
Assembly: Libplanet.Net.dll
Syntax
public class ConsensusContext : IDisposable
Constructors
| Improve this Doc View SourceConsensusContext(IConsensusMessageCommunicator, BlockChain, PrivateKey, TimeSpan, ContextTimeoutOption)
Initializes a new instance of the ConsensusContext class.
Declaration
public ConsensusContext(IConsensusMessageCommunicator consensusMessageCommunicator, BlockChain blockChain, PrivateKey privateKey, TimeSpan newHeightDelay, ContextTimeoutOption contextTimeoutOption)
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. |
PrivateKey | privateKey | A PrivateKey for signing message and blocks. |
TimeSpan | newHeightDelay | A time delay in starting the consensus for the next height block. Libplanet.Net.Consensus.ConsensusContext.OnTipChanged(System.Object,System.ValueTuple{Libplanet.Types.Blocks.Block,Libplanet.Types.Blocks.Block}) |
ContextTimeoutOption | contextTimeoutOption | A ContextTimeoutOption for configuring a timeout for each Step. |
Properties
| Improve this Doc View SourceHeight
The index of block that ConsensusContext is watching. The value can be changed by starting a consensus or appending a block.
Declaration
public long Height { get; }
Property Value
Type | Description |
---|---|
Int64 | If NewHeight(Int64) or Libplanet.Net.Consensus.ConsensusContext.OnTipChanged(System.Object,System.ValueTuple{Libplanet.Types.Blocks.Block,Libplanet.Types.Blocks.Block}) is called
before, returns current working height, otherwise returns |
See Also
Round
Declaration
public long Round { get; }
Property Value
Type | Description |
---|---|
Int64 | If there is Context for Height returns the round of current Context, or otherwise returns -1. |
Step
Declaration
public ConsensusStep Step { get; }
Property Value
Type | Description |
---|---|
ConsensusStep | If there is Context for Height returns the step of current Context, or otherwise returns Null. |
Methods
| Improve this Doc View SourceDispose()
A class that maintains the states of a Context for block indices now in consensus.
Declaration
public void Dispose()
HandleMaj23(Maj23)
Handles a received Maj23 and return message to fetch.
Declaration
public VoteSetBits HandleMaj23(Maj23 maj23)
Parameters
Type | Name | Description |
---|---|---|
Maj23 | maj23 | The Maj23 received from any validator. |
Returns
Type | Description |
---|---|
VoteSetBits | An IEnumerable<T> to reply back. |
Remarks
This method does not update state of the context.
HandleMessage(ConsensusMsg)
Handles a received ConsensusMsg by either dispatching it to the right Context or discarding it.
In particular, this discards consensusMessage
with
Height less than Height. Otherwise,
given consensusMessage
is passed on to a Context
with Height the same as Height of
consensusMessage
. If there is no such Context,
then a new Context is created for the dispatch.
Declaration
public bool HandleMessage(ConsensusMsg consensusMessage)
Parameters
Type | Name | Description |
---|---|---|
ConsensusMsg | consensusMessage | The ConsensusMsg received from any validator. |
Returns
Type | Description |
---|---|
Boolean | true if |
HandleProposalClaim(ProposalClaim)
A class that maintains the states of a Context for block indices now in consensus.
Declaration
public Proposal HandleProposalClaim(ProposalClaim proposalClaim)
Parameters
Type | Name | Description |
---|---|---|
ProposalClaim | proposalClaim |
Returns
Type | Description |
---|---|
Proposal |
HandleVoteSetBits(VoteSetBits)
Handles a received VoteSetBits and return message to fetch.
Declaration
public IEnumerable<ConsensusMsg> HandleVoteSetBits(VoteSetBits voteSetBits)
Parameters
Type | Name | Description |
---|---|---|
VoteSetBits | voteSetBits | The VoteSetBits received from any validator. |
Returns
Type | Description |
---|---|
IEnumerable<ConsensusMsg> | An IEnumerable<T> to reply back. |
Remarks
This method does not update state of the context.
NewHeight(Int64)
Starts a new Context for given height
.
Declaration
public void NewHeight(long height)
Parameters
Type | Name | Description |
---|---|---|
Int64 | height | The height of a new Context to start. |
Remarks
The method is also called when the tip of the BlockChain is changed (i.e., committed, synchronized).
Exceptions
Type | Condition |
---|---|
InvalidHeightIncreasingException | Thrown if given
|
ToString()
Returns the summary for ConsensusContext.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | Returns the current height Context. if there's no instance of Context for current height, returns "No context". |