Class ValidatorSet
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Inherited Members
Namespace: Libplanet.Types.Consensus
Assembly: Libplanet.Types.dll
Syntax
public class ValidatorSet : IEquatable<ValidatorSet>, IBencodable
Constructors
| Improve this Doc View SourceValidatorSet()
Creates an instance of an empty ValidatorSet. to Validators.
Declaration
public ValidatorSet()
ValidatorSet(IValue)
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public ValidatorSet(IValue bencoded)
Parameters
Type | Name | Description |
---|---|---|
Bencodex.Types.IValue | bencoded |
ValidatorSet(List<Validator>)
Creates an instance of ValidatorSet. Given validators
is ordered internally by Address before getting assigned
to Validators.
Declaration
public ValidatorSet(List<Validator> validators)
Parameters
Type | Name | Description |
---|---|---|
List<Validator> | validators | The List<T> of validators to use. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when one of the following is true: |
Properties
| Improve this Doc View SourceBencoded
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public IValue Bencoded { get; }
Property Value
Type | Description |
---|---|
Bencodex.Types.IValue |
Item[Int32]
Gets the validator at given index
.
Declaration
public Validator this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index to search. |
Property Value
Type | Description |
---|---|
Validator | The validator at given |
OneThirdCount
The one third of validator count, rounded down.
Declaration
public int OneThirdCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
OneThirdPower
The one third of validator total power, rounded down.
Declaration
public BigInteger OneThirdPower { get; }
Property Value
Type | Description |
---|---|
BigInteger |
PublicKeys
An ImmutableList<T> of public keys of validators. This is guaranteed to be ordered by Address.
Declaration
public ImmutableList<PublicKey> PublicKeys { get; }
Property Value
Type | Description |
---|---|
ImmutableList<PublicKey> |
TotalCount
The total number of validators.
Declaration
public int TotalCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
TotalPower
The total power of validators.
Declaration
public BigInteger TotalPower { get; }
Property Value
Type | Description |
---|---|
BigInteger |
TwoThirdsCount
The two thirds of validator count, rounded down.
Declaration
public int TwoThirdsCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
TwoThirdsPower
The two thirds of validator total power, rounded down.
Declaration
public BigInteger TwoThirdsPower { get; }
Property Value
Type | Description |
---|---|
BigInteger |
Validators
An ImmutableList<T> of validators. This is guaranteed to be ordered by Address.
Declaration
public ImmutableList<Validator> Validators { get; }
Property Value
Type | Description |
---|---|
ImmutableList<Validator> |
Methods
| Improve this Doc View SourceContains(Validator)
Checks if given validator
is a member of ValidatorSet.
Checks both of PublicKey and Power.
Declaration
public bool Contains(Validator validator)
Parameters
Type | Name | Description |
---|---|---|
Validator | validator | The Validator to check. |
Returns
Type | Description |
---|---|
Boolean | true if given |
ContainsPublicKey(PublicKey)
Checks if given publicKey
is a member of ValidatorSet.
Declaration
public bool ContainsPublicKey(PublicKey publicKey)
Parameters
Type | Name | Description |
---|---|---|
PublicKey | publicKey |
Returns
Type | Description |
---|---|
Boolean | true if given |
Equals(ValidatorSet)
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public bool Equals(ValidatorSet other)
Parameters
Type | Name | Description |
---|---|---|
ValidatorSet | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(Object)
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc View SourceFindIndex(PublicKey)
Gets the index of given publicKey
.
Declaration
public int FindIndex(PublicKey publicKey)
Parameters
Type | Name | Description |
---|---|---|
PublicKey | publicKey | The PublicKey to find index. |
Returns
Type | Description |
---|---|
Int32 | The index of given |
GetHashCode()
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
| Improve this Doc View SourceGetProposer(Int64, Int32)
Gets the proposer for a given context.
Declaration
public Validator GetProposer(long height, int round)
Parameters
Type | Name | Description |
---|---|---|
Int64 | height | The height of the context under consideration. |
Int32 | round | The round of the context under consideration. |
Returns
Type | Description |
---|---|
Validator | A Validator deterministically chosen from
Validators, |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when Validators is empty. |
GetValidator(PublicKey)
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public Validator GetValidator(PublicKey publicKey)
Parameters
Type | Name | Description |
---|---|---|
PublicKey | publicKey |
Returns
Type | Description |
---|---|
Validator |
GetValidators(IEnumerable<PublicKey>)
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public ImmutableList<Validator> GetValidators(IEnumerable<PublicKey> publicKeys)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<PublicKey> | publicKeys |
Returns
Type | Description |
---|---|
ImmutableList<Validator> |
GetValidatorsPower(List<PublicKey>)
A wrapper class for a List<T> of Validators. This standardizes the ordering of validators by Address.
Declaration
public BigInteger GetValidatorsPower(List<PublicKey> publicKeys)
Parameters
Type | Name | Description |
---|---|---|
List<PublicKey> | publicKeys |
Returns
Type | Description |
---|---|
BigInteger |
Update(Validator)
Creates a new ValidatorSet that has been updated with
given validator
according to the following rule:
-
If
validator
's power is zero, the Validator with the same PublicKey is removed, if it exists. If no matching Validator is found, no change is made. -
If
validator
's power is positive, the Validator with the same PublicKey is overwritten, if it exists. If no matching Validator is found,validator
is added to the set.
Declaration
[Pure]
public ValidatorSet Update(Validator validator)
Parameters
Type | Name | Description |
---|---|---|
Validator | validator | The Validator to update. |
Returns
Type | Description |
---|---|
ValidatorSet | New ValidatorSet updated with
given |
ValidateBlockCommitValidators(BlockCommit)
Checks whether Votes is ordered by Address of each ValidatorPublicKey.
Declaration
public bool ValidateBlockCommitValidators(BlockCommit blockCommit)
Parameters
Type | Name | Description |
---|---|---|
BlockCommit | blockCommit | The BlockCommit to check. |
Returns
Type | Description |
---|---|
Boolean | true if the Votes is ordered, false otherwise. |