[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-10-10 16:03:50 +00:00
parent 82064e3a23
commit 2046ea45bc

View File

@ -1,5 +1,6 @@
import random import random
class Validator: class Validator:
def __init__(self, name: str, stake: int) -> None: def __init__(self, name: str, stake: int) -> None:
""" """
@ -12,6 +13,7 @@ class Validator:
self.name = name self.name = name
self.stake = stake self.stake = stake
def choose_validator(validators: list[Validator]) -> Validator: def choose_validator(validators: list[Validator]) -> Validator:
""" """
Selects a validator to create the next block based on the weight of their stake. Selects a validator to create the next block based on the weight of their stake.
@ -32,6 +34,7 @@ def choose_validator(validators: list[Validator]) -> Validator:
""" """
total_stake = sum(v.stake for v in validators) total_stake = sum(v.stake for v in validators)
weighted_validators = [(v, v.stake / total_stake) for v in validators] weighted_validators = [(v, v.stake / total_stake) for v in validators]
selected = random.choices([v[0] for v in weighted_validators], selected = random.choices(
weights=[v[1] for v in weighted_validators]) [v[0] for v in weighted_validators], weights=[v[1] for v in weighted_validators]
)
return selected[0] return selected[0]