[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:12:08 +00:00
parent df4c444095
commit 8b9ff8d4f3

View File

@ -1,5 +1,6 @@
import random
class Validator:
def __init__(self, name: str, stake: int) -> None:
"""
@ -12,6 +13,7 @@ class Validator:
self.name = name
self.stake = stake
def choose_validator(validators: list[Validator]) -> Validator:
"""
Selects a validator to create the next block based on the weight of their stake.
@ -31,11 +33,8 @@ def choose_validator(validators: list[Validator]) -> Validator:
True
"""
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],
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]