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(ConsensusContext.DelegateBroadcastMessage, BlockChain, PrivateKey, TimeSpan, ContextTimeoutOption)
Initializes a new instance of the ConsensusContext class.
Declaration
public ConsensusContext(ConsensusContext.DelegateBroadcastMessage broadcastMessage, BlockChain blockChain, PrivateKey privateKey, TimeSpan newHeightDelay, ContextTimeoutOption contextTimeoutOption)
Parameters
Type | Name | Description |
---|---|---|
ConsensusContext.DelegateBroadcastMessage | broadcastMessage | A delegate method that will broadcasting given ConsensusMsg to 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.Blocks.Block,Libplanet.Blocks.Block}) |
ContextTimeoutOption | contextTimeoutOption | A ContextTimeoutOption for configuring a timeout for each Step. |
Properties
| Improve this Doc View SourceBroadcastMessage
A class that maintains the states of a Context for block indices now in consensus.
Declaration
public ConsensusContext.DelegateBroadcastMessage BroadcastMessage { get; }
Property Value
Type | Description |
---|---|
ConsensusContext.DelegateBroadcastMessage |
Height
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.Blocks.Block,Libplanet.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 Step Step { get; }
Property Value
Type | Description |
---|---|
Step | 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()
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 |
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". |