Cleanup
This commit is contained in:
parent
1daaf7412d
commit
0be2b8e620
|
@ -12,7 +12,7 @@ from typing import (
|
|||
|
||||
|
||||
PHASE0_IMPORTS = '''from typing import (
|
||||
Any, Callable, Dict, Set, Sequence, Tuple,
|
||||
Any, Dict, Set, Sequence, Tuple,
|
||||
)
|
||||
|
||||
from dataclasses import (
|
||||
|
@ -37,7 +37,7 @@ from eth2spec.utils.bls import (
|
|||
from eth2spec.utils.hash_function import hash
|
||||
'''
|
||||
PHASE1_IMPORTS = '''from typing import (
|
||||
Any, Callable, Dict, Optional, Set, Sequence, MutableSequence, Tuple,
|
||||
Any, Dict, Optional, Set, Sequence, MutableSequence, Tuple,
|
||||
)
|
||||
|
||||
from dataclasses import (
|
||||
|
|
|
@ -147,7 +147,7 @@ We define the following Python custom types for type hinting and readability:
|
|||
| `ValidatorIndex` | `uint64` | a validator registry index |
|
||||
| `Gwei` | `uint64` | an amount in Gwei |
|
||||
| `Version` | `Bytes4` | a fork version number |
|
||||
| `Hash` | `Bytes32` | a hashed result |
|
||||
| `Hash` | `Bytes32` | a hash |
|
||||
| `BLSPubkey` | `Bytes48` | a BLS12-381 public key |
|
||||
| `BLSSignature` | `Bytes96` | a BLS12-381 signature |
|
||||
|
||||
|
@ -158,7 +158,6 @@ The following values are (non-configurable) constants used throughout the specif
|
|||
| Name | Value |
|
||||
| - | - |
|
||||
| `FAR_FUTURE_EPOCH` | `Epoch(2**64 - 1)` |
|
||||
| `ZERO_HASH` | `Hash(b'\x00' * 32)` |
|
||||
| `BASE_REWARDS_PER_EPOCH` | `5` |
|
||||
| `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) |
|
||||
| `SECONDS_PER_DAY` | `86400` |
|
||||
|
@ -542,11 +541,10 @@ class BeaconState(Container):
|
|||
#### `integer_squareroot`
|
||||
|
||||
```python
|
||||
def integer_squareroot(n: int) -> int:
|
||||
def integer_squareroot(n: uint64) -> uint64:
|
||||
"""
|
||||
Return the largest integer ``x`` such that ``x**2 <= n``.
|
||||
"""
|
||||
assert n >= 0
|
||||
x = n
|
||||
y = (x + 1) // 2
|
||||
while y < x:
|
||||
|
@ -1204,7 +1202,7 @@ def process_slot(state: BeaconState) -> None:
|
|||
previous_state_root = hash_tree_root(state)
|
||||
state.state_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_state_root
|
||||
# Cache latest block header state root
|
||||
if state.latest_block_header.state_root == ZERO_HASH:
|
||||
if state.latest_block_header.state_root == Hash():
|
||||
state.latest_block_header.state_root = previous_state_root
|
||||
# Cache block root
|
||||
previous_block_root = signing_root(state.latest_block_header)
|
||||
|
@ -1527,7 +1525,7 @@ def process_block_header(state: BeaconState, block: BeaconBlock) -> None:
|
|||
state.latest_block_header = BeaconBlockHeader(
|
||||
slot=block.slot,
|
||||
parent_root=block.parent_root,
|
||||
state_root=ZERO_HASH, # Overwritten in the next `process_slot` call
|
||||
state_root=Hash(), # Overwritten in the next `process_slot` call
|
||||
body_root=hash_tree_root(block.body),
|
||||
)
|
||||
# Verify proposer is not slashed
|
||||
|
@ -1568,15 +1566,14 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
|
|||
# Verify that there are no duplicate transfers
|
||||
assert len(body.transfers) == len(set(body.transfers))
|
||||
|
||||
all_operations = (
|
||||
for operations, function in (
|
||||
(body.proposer_slashings, process_proposer_slashing),
|
||||
(body.attester_slashings, process_attester_slashing),
|
||||
(body.attestations, process_attestation),
|
||||
(body.deposits, process_deposit),
|
||||
(body.voluntary_exits, process_voluntary_exit),
|
||||
(body.transfers, process_transfer),
|
||||
) # type: Sequence[Tuple[List, Callable]]
|
||||
for operations, function in all_operations:
|
||||
):
|
||||
for operation in operations:
|
||||
function(state, operation)
|
||||
```
|
||||
|
@ -1651,7 +1648,7 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:
|
|||
assert data.crosslink.parent_root == hash_tree_root(parent_crosslink)
|
||||
assert data.crosslink.start_epoch == parent_crosslink.end_epoch
|
||||
assert data.crosslink.end_epoch == min(data.target.epoch, parent_crosslink.end_epoch + MAX_EPOCHS_PER_CROSSLINK)
|
||||
assert data.crosslink.data_root == ZERO_HASH # [to be removed in phase 1]
|
||||
assert data.crosslink.data_root == Hash() # [to be removed in phase 1]
|
||||
|
||||
# Check signature
|
||||
validate_indexed_attestation(state, get_indexed_attestation(state, attestation))
|
||||
|
|
|
@ -595,7 +595,7 @@ def process_chunk_challenge_response(state: BeaconState,
|
|||
# Verify chunk index
|
||||
assert response.chunk_index == challenge.chunk_index
|
||||
# Verify bit challenge data is null
|
||||
assert response.chunk_bits_branch == [] and response.chunk_bits_leaf == ZERO_HASH
|
||||
assert response.chunk_bits_branch == [] and response.chunk_bits_leaf == Hash()
|
||||
# Verify minimum delay
|
||||
assert get_current_epoch(state) >= challenge.inclusion_epoch + ACTIVATION_EXIT_DELAY
|
||||
# Verify the chunk matches the crosslink data root
|
||||
|
|
|
@ -309,11 +309,11 @@ def is_valid_shard_block(beacon_blocks: Sequence[BeaconBlock],
|
|||
assert beacon_block.slot <= candidate.slot
|
||||
|
||||
# Check state root
|
||||
assert candidate.state_root == ZERO_HASH # [to be removed in phase 2]
|
||||
assert candidate.state_root == Hash() # [to be removed in phase 2]
|
||||
|
||||
# Check parent block
|
||||
if candidate.slot == PHASE_1_FORK_SLOT:
|
||||
assert candidate.parent_root == ZERO_HASH
|
||||
assert candidate.parent_root == Hash()
|
||||
else:
|
||||
parent_block = next(
|
||||
(block for block in valid_shard_blocks if signing_root(block) == candidate.parent_root),
|
||||
|
@ -395,7 +395,7 @@ def is_valid_beacon_attestation(shard: Shard,
|
|||
|
||||
# Check previous attestation
|
||||
if candidate.data.previous_crosslink.epoch <= PHASE_1_FORK_EPOCH:
|
||||
assert candidate.data.previous_crosslink.data_root == ZERO_HASH
|
||||
assert candidate.data.previous_crosslink.data_root == Hash()
|
||||
else:
|
||||
previous_attestation = next(
|
||||
(attestation for attestation in valid_attestations if
|
||||
|
|
|
@ -43,7 +43,7 @@ def build_attestation_data(spec, state, slot, shard):
|
|||
shard=shard,
|
||||
start_epoch=parent_crosslink.end_epoch,
|
||||
end_epoch=min(spec.slot_to_epoch(slot), parent_crosslink.end_epoch + spec.MAX_EPOCHS_PER_CROSSLINK),
|
||||
data_root=spec.ZERO_HASH,
|
||||
data_root=spec.Hash(),
|
||||
parent_root=hash_tree_root(parent_crosslink),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -59,7 +59,7 @@ def build_empty_block(spec, state, slot=None, signed=False):
|
|||
empty_block.slot = slot
|
||||
empty_block.body.eth1_data.deposit_count = state.eth1_deposit_index
|
||||
previous_block_header = deepcopy(state.latest_block_header)
|
||||
if previous_block_header.state_root == spec.ZERO_HASH:
|
||||
if previous_block_header.state_root == spec.Hash():
|
||||
previous_block_header.state_root = state.hash_tree_root()
|
||||
empty_block.parent_root = signing_root(previous_block_header)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ def create_genesis_state(spec, num_validators):
|
|||
eth1_data=spec.Eth1Data(
|
||||
deposit_root=deposit_root,
|
||||
deposit_count=num_validators,
|
||||
block_hash=spec.ZERO_HASH,
|
||||
block_hash=spec.Hash(),
|
||||
),
|
||||
latest_block_header=spec.BeaconBlockHeader(body_root=spec.hash_tree_root(spec.BeaconBlockBody())),
|
||||
)
|
||||
|
|
|
@ -195,7 +195,7 @@ def test_bad_merkle_proof(spec, state):
|
|||
deposit = prepare_state_and_deposit(spec, state, validator_index, amount)
|
||||
|
||||
# mess up merkle branch
|
||||
deposit.proof[5] = spec.ZERO_HASH
|
||||
deposit.proof[5] = spec.Hash()
|
||||
|
||||
sign_deposit_data(spec, deposit.data, privkeys[validator_index], state=state)
|
||||
|
||||
|
|
|
@ -360,7 +360,7 @@ def test_non_existent_recipient(spec, state):
|
|||
@spec_state_test
|
||||
def test_invalid_pubkey(spec, state):
|
||||
transfer = get_valid_transfer(spec, state, signed=True)
|
||||
state.validators[transfer.sender].withdrawal_credentials = spec.ZERO_HASH
|
||||
state.validators[transfer.sender].withdrawal_credentials = spec.Hash()
|
||||
|
||||
# un-activate so validator can transfer
|
||||
state.validators[transfer.sender].activation_eligibility_epoch = spec.FAR_FUTURE_EPOCH
|
||||
|
|
|
@ -63,7 +63,7 @@ def test_empty_block_transition(spec, state):
|
|||
|
||||
assert len(state.eth1_data_votes) == pre_eth1_votes + 1
|
||||
assert spec.get_block_root_at_slot(state, pre_slot) == block.parent_root
|
||||
assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.ZERO_HASH
|
||||
assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Hash()
|
||||
|
||||
|
||||
@with_all_phases
|
||||
|
@ -98,7 +98,7 @@ def test_skipped_slots(spec, state):
|
|||
yield 'post', state
|
||||
|
||||
assert state.slot == block.slot
|
||||
assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.ZERO_HASH
|
||||
assert spec.get_randao_mix(state, spec.get_current_epoch(state)) != spec.Hash()
|
||||
for slot in range(pre_slot, state.slot):
|
||||
assert spec.get_block_root_at_slot(state, slot) == block.parent_root
|
||||
|
||||
|
|
Loading…
Reference in New Issue