Skip to content

Commit

Permalink
Add validation for thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
cyc60 committed Feb 5, 2024
1 parent ba5edbd commit fa604bb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sw_utils/protocol_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def build_protocol_config(
config_data: dict, rewards_threshold: int = 0, validators_threshold: int = 0
config_data: dict, rewards_threshold: int | None = None, validators_threshold: int | None = None
) -> ProtocolConfig:
oracles = []
for oracle in config_data['oracles']:
Expand All @@ -13,10 +13,10 @@ def build_protocol_config(
)
)

if rewards_threshold and not 1 <= rewards_threshold <= len(oracles):
if rewards_threshold is not None and not 1 <= rewards_threshold <= len(oracles):
raise ValueError('Invalid rewards threshold')

if validators_threshold and not 1 <= validators_threshold <= len(oracles):
if validators_threshold is not None and not 1 <= validators_threshold <= len(oracles):
raise ValueError('Invalid validators threshold')

public_keys = [oracle.public_key for oracle in oracles]
Expand All @@ -30,8 +30,8 @@ def build_protocol_config(

return ProtocolConfig(
oracles=oracles,
rewards_threshold=rewards_threshold,
validators_threshold=validators_threshold,
rewards_threshold=rewards_threshold or 0,
validators_threshold=validators_threshold or 0,
exit_signature_recover_threshold=exit_signature_recover_threshold,
supported_relays=config_data['supported_relays'],
vault_fee_max_bps=config_data['vault_max_fee'],
Expand Down

0 comments on commit fa604bb

Please sign in to comment.