Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8-ish cleanup #997

Merged
merged 2 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions scripts/phase0/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
def build_phase0_spec(sourcefile, outfile):
code_lines = []
code_lines.append("""

from typing import (
Any,
Callable,
Dict,
List,
NewType,
Expand All @@ -17,19 +15,16 @@ def build_phase0_spec(sourcefile, outfile):
from eth2spec.utils.minimal_ssz import *
from eth2spec.utils.bls_stub import *


""")
""")
for i in (1, 2, 3, 4, 8, 32, 48, 96):
code_lines.append("def int_to_bytes%d(x): return x.to_bytes(%d, 'little')" % (i, i))

code_lines.append("""

# stub, will get overwritten by real var
SLOTS_PER_EPOCH = 64


def slot_to_epoch(x): return x // SLOTS_PER_EPOCH


Slot = NewType('Slot', int) # uint64
Epoch = NewType('Epoch', int) # uint64
Shard = NewType('Shard', int) # uint64
Expand All @@ -38,9 +33,8 @@ def slot_to_epoch(x): return x // SLOTS_PER_EPOCH
Bytes32 = NewType('Bytes32', bytes) # bytes32
BLSPubkey = NewType('BLSPubkey', bytes) # bytes48
BLSSignature = NewType('BLSSignature', bytes) # bytes96
Any = None
Store = None
""")
""")

code_lines += function_puller.get_spec(sourcefile)

Expand Down Expand Up @@ -88,7 +82,7 @@ def apply_constants_preset(preset: Dict[str, Any]):

# Deal with derived constants
global_vars['GENESIS_EPOCH'] = slot_to_epoch(GENESIS_SLOT)

# Initialize SSZ types again, to account for changed lengths
init_SSZ_types()
""")
Expand Down
7 changes: 4 additions & 3 deletions scripts/phase0/function_puller.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def get_spec(file_name: str) -> List[str]:
code_lines.append('')
for type_line in ssz_type:
code_lines.append(' ' + type_line)
code_lines.append('')
code_lines.append('\n')
code_lines.append('ssz_types = [' + ', '.join([f'\'{ssz_type_name}\'' for (ssz_type_name, _) in type_defs]) + ']')
code_lines.append('')
code_lines.append('def get_ssz_type_by_name(name: str) -> SSZType: return globals()[name]')
code_lines.append('\n')
code_lines.append('def get_ssz_type_by_name(name: str) -> SSZType:')
code_lines.append(' return globals()[name]')
code_lines.append('')
return code_lines
14 changes: 6 additions & 8 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ def is_slashable_validator(validator: Validator, epoch: Epoch) -> bool:
Check if ``validator`` is slashable.
"""
return validator.slashed is False and (validator.activation_epoch <= epoch < validator.withdrawable_epoch)

```

### `get_active_validator_indices`
Expand Down Expand Up @@ -1250,7 +1249,7 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
process_deposit(state, deposit)

# Process genesis activations
for index, validator in enumerate(state.validator_registry):
for validator in state.validator_registry:
if validator.effective_balance >= MAX_EFFECTIVE_BALANCE:
validator.activation_eligibility_epoch = GENESIS_EPOCH
validator.activation_epoch = GENESIS_EPOCH
Expand Down Expand Up @@ -1366,7 +1365,7 @@ def get_winning_crosslink_and_attesting_indices(state: BeaconState, shard: Shard
if hash_tree_root(state.current_crosslinks[shard]) in (c.previous_crosslink_root, hash_tree_root(c))
]
if len(candidate_crosslinks) == 0:
return Crosslink(epoch=GENESIS_EPOCH, previous_crosslink_root=ZERO_HASH, crosslink_data_root=ZERO_HASH), []
return Crosslink(epoch=GENESIS_EPOCH), []

def get_attestations_for(crosslink: Crosslink) -> List[PendingAttestation]:
return [a for a in shard_attestations if get_crosslink_from_attestation_data(state, a.data) == crosslink]
Expand Down Expand Up @@ -1461,15 +1460,14 @@ def get_base_reward(state: BeaconState, index: ValidatorIndex) -> Gwei:
if adjusted_quotient == 0:
return 0
return state.validator_registry[index].effective_balance // adjusted_quotient // BASE_REWARDS_PER_EPOCH

```

```python
def get_attestation_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]:
previous_epoch = get_previous_epoch(state)
total_balance = get_total_active_balance(state)
rewards = [0 for index in range(len(state.validator_registry))]
penalties = [0 for index in range(len(state.validator_registry))]
rewards = [0 for _ in range(len(state.validator_registry))]
penalties = [0 for _ in range(len(state.validator_registry))]
eligible_validator_indices = [
index for index, v in enumerate(state.validator_registry)
if is_active_validator(v, previous_epoch) or (v.slashed and previous_epoch + 1 < v.withdrawable_epoch)
Expand Down Expand Up @@ -1509,8 +1507,8 @@ def get_attestation_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]:

```python
def get_crosslink_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]:
rewards = [0 for index in range(len(state.validator_registry))]
penalties = [0 for index in range(len(state.validator_registry))]
rewards = [0 for _ in range(len(state.validator_registry))]
penalties = [0 for _ in range(len(state.validator_registry))]
for slot in range(get_epoch_start_slot(get_previous_epoch(state)), get_epoch_start_slot(get_current_epoch(state))):
epoch = slot_to_epoch(slot)
for crosslink_committee, shard in get_crosslink_committees_at_slot(state, slot):
Expand Down
8 changes: 7 additions & 1 deletion test_libs/gen_helpers/gen_base/gen_typing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from typing import Callable, Dict, Tuple, Any
from typing import (
Any,
Callable,
Dict,
Tuple,
)


TestCase = Dict[str, Any]
TestSuite = Dict[str, Any]
Expand Down