blockchain.proof_of_stake¶
Classes¶
Functions¶
|
Selects a validator to create the next block based on the weight of their stake. |
Module Contents¶
- blockchain.proof_of_stake.choose_validator(validators: list[Validator]) Validator¶
Selects a validator to create the next block based on the weight of their stake.
The higher the stake, the greater the chance to be selected.
- Args:
validators (list[Validator]): A list of Validator objects.
- Returns:
Validator: The selected validator based on weighted random selection.
- Example:
>>> validators = [Validator("Alice", 50), Validator("Bob", 30)] >>> chosen = choose_validator(validators) >>> isinstance(chosen, Validator) True