update remerkleable; mul/div bound checks, update config loading

This commit is contained in:
protolambda 2020-04-06 18:40:09 +02:00
parent 71b0640694
commit 13d1303db8
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
3 changed files with 12 additions and 7 deletions

View File

@ -499,7 +499,7 @@ setup(
"pycryptodome==3.9.4",
"py_ecc==2.0.0",
"dataclasses==0.6",
"remerkleable==0.1.12",
"remerkleable==0.1.13",
"ruamel.yaml==0.16.5",
"lru-dict==1.1.6"
]

View File

@ -8,13 +8,18 @@ config: Dict[str, Any] = {}
# Access to overwrite spec constants based on configuration
# This is called by the spec module after declaring its globals, and applies the loaded presets.
def apply_constants_config(spec_globals: Dict[str, Any]) -> None:
def apply_constants_config(spec_globals: Dict[str, Any], warn_if_unknown: bool = False) -> None:
global config
for k, v in config.items():
if k.startswith('DOMAIN_'):
spec_globals[k] = spec_globals['DomainType'](v) # domain types are defined as bytes in the configs
# the spec should have default values for everything, if not, the config key is invalid.
if k in spec_globals:
# Keep the same type as the default value indicates (which may be an SSZ basic type subclass, e.g. 'Gwei')
spec_globals[k] = spec_globals[k].__class__(v)
else:
spec_globals[k] = v
# Note: Phase 0 spec will not know the phase 1 config values.
# Yet, during debugging you can enable explicit warnings.
if warn_if_unknown:
print(f"WARNING: unknown config key: '{k}' with value: '{v}'")
# Load presets from a file, and then prepares the global config setting. This does not apply the config.

View File

@ -24,7 +24,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support
raise Exception(f"cannot include attestations in epoch ${epoch} from epoch ${current_epoch}")
total_balance = spec.get_total_active_balance(state)
remaining_balance = total_balance * 2 // 3
remaining_balance = int(total_balance * 2 // 3) # can become negative
start_slot = spec.compute_start_slot_at_epoch(epoch)
for slot in range(start_slot, start_slot + spec.SLOTS_PER_EPOCH):
@ -42,7 +42,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support
aggregation_bits = [0] * len(committee)
for v in range(len(committee) * 2 // 3 + 1):
if remaining_balance > 0:
remaining_balance -= state.validators[v].effective_balance
remaining_balance -= int(state.validators[v].effective_balance)
aggregation_bits[v] = 1
else:
break