-
Notifications
You must be signed in to change notification settings - Fork 997
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
Add mypy type hinting check #1166
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9fc197a
class Bytes32
hwwhww 8b64f37
Make uint64 be `class` for type hinting
hwwhww 9f45418
WIP!
hwwhww 6f526ad
flake8 length
hwwhww f2c3352
Add mypy check in CI
hwwhww 7a36682
Make phase0 pass
hwwhww 8a54203
Modify the mypy config
hwwhww 48e8164
Add phase1 type hinting checks and fix many bugs
hwwhww 8577cff
enable mypy check in CI
hwwhww 00a68e2
Define Custom Types via function_puller
hwwhww b772b03
Handle `BLSPubkey` and `BLSSignature`
hwwhww 9b77ec1
Version: Bytes4
hwwhww e93ba51
More clean up
hwwhww 18ebd2a
Bytes32 -> Hash
hwwhww 9af9bbf
Merge branch 'dev' into mypy
hwwhww 01e9f18
Merge branch 'dev' into mypy
hwwhww dd79a0e
Merge branch 'dev' into mypy
hwwhww f4de5e3
fix review comment: one line cache set
protolambda 207f632
resolve other ret comment
protolambda f0e909c
add mypy cache to gitignore
protolambda 346e61d
make epoch pattern similar to exit-epoch loop
protolambda 0600419
remove unnecessary cast
protolambda 7d2f0a9
clean up
hwwhww 6df75ec
cleanup unused byte part of builder
protolambda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
Callable, | ||
Dict, | ||
List, | ||
Optional, | ||
Set, | ||
Tuple, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,8 +79,8 @@ class ShardBlockBody(Container): | |
```python | ||
class ShardAttestation(Container): | ||
class data(Container): | ||
slot: uint64 | ||
shard: uint64 | ||
slot: Slot | ||
shard: Shard | ||
shard_block_root: Bytes32 | ||
aggregation_bitfield: bytes | ||
aggregate_signature: Bytes96 | ||
|
@@ -90,8 +90,8 @@ class ShardAttestation(Container): | |
|
||
```python | ||
class ShardBlock(Container): | ||
slot: uint64 | ||
shard: uint64 | ||
slot: Slot | ||
shard: Shard | ||
beacon_chain_root: Bytes32 | ||
parent_root: Bytes32 | ||
data: ShardBlockBody | ||
|
@@ -104,8 +104,8 @@ class ShardBlock(Container): | |
|
||
```python | ||
class ShardBlockHeader(Container): | ||
slot: uint64 | ||
shard: uint64 | ||
slot: Slot | ||
shard: Shard | ||
beacon_chain_root: Bytes32 | ||
parent_root: Bytes32 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the hashes can be of type |
||
body_root: Bytes32 | ||
|
@@ -138,8 +138,8 @@ def get_period_committee(state: BeaconState, | |
### `get_switchover_epoch` | ||
|
||
```python | ||
def get_switchover_epoch(state: BeaconState, epoch: Epoch, index: ValidatorIndex): | ||
earlier_start_epoch = epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD * 2 | ||
def get_switchover_epoch(state: BeaconState, epoch: Epoch, index: ValidatorIndex) -> int: | ||
earlier_start_epoch = Epoch(epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD * 2) | ||
return (bytes_to_int(hash(generate_seed(state, earlier_start_epoch) + int_to_bytes(index, length=3)[0:8])) | ||
% PERSISTENT_COMMITTEE_PERIOD) | ||
``` | ||
|
@@ -154,19 +154,19 @@ def get_persistent_committee(state: BeaconState, | |
Return the persistent committee for the given ``shard`` at the given ``slot``. | ||
""" | ||
epoch = slot_to_epoch(slot) | ||
earlier_start_epoch = epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD * 2 | ||
later_start_epoch = epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD | ||
earlier_start_epoch = Epoch(epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD * 2) | ||
later_start_epoch = Epoch(epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD) | ||
|
||
committee_count = max( | ||
len(get_active_validator_indices(state.validator_registry, earlier_start_epoch)) // | ||
len(get_active_validator_indices(state, earlier_start_epoch)) // | ||
(SHARD_COUNT * TARGET_COMMITTEE_SIZE), | ||
len(get_active_validator_indices(state.validator_registry, later_start_epoch)) // | ||
len(get_active_validator_indices(state, later_start_epoch)) // | ||
(SHARD_COUNT * TARGET_COMMITTEE_SIZE), | ||
) + 1 | ||
|
||
index = slot % committee_count | ||
earlier_committee = get_period_committee(state, shard, earlier_start_epoch, index, committee_count) | ||
later_committee = get_period_committee(state, shard, later_start_epoch, index, committee_count) | ||
earlier_committee = get_period_committee(state, earlier_start_epoch, shard, index, committee_count) | ||
later_committee = get_period_committee(state, later_start_epoch, shard, index, committee_count) | ||
|
||
# Take not-yet-cycled-out validators from earlier committee and already-cycled-in validators from | ||
# later committee; return a sorted list of the union of the two, deduplicated | ||
|
@@ -181,7 +181,7 @@ def get_persistent_committee(state: BeaconState, | |
```python | ||
def get_shard_proposer_index(state: BeaconState, | ||
shard: Shard, | ||
slot: Slot) -> ValidatorIndex: | ||
slot: Slot) -> Optional[ValidatorIndex]: | ||
# Randomly shift persistent committee | ||
persistent_committee = get_persistent_committee(state, shard, slot) | ||
seed = hash(state.current_shuffling_seed + int_to_bytes(shard, length=8) + int_to_bytes(slot, length=8)) | ||
|
@@ -231,7 +231,7 @@ def verify_shard_attestation_signature(state: BeaconState, | |
pubkey=bls_aggregate_pubkeys(pubkeys), | ||
message_hash=data.shard_block_root, | ||
signature=attestation.aggregate_signature, | ||
domain=get_domain(state, slot_to_epoch(data.slot), DOMAIN_SHARD_ATTESTER) | ||
domain=get_domain(state, DOMAIN_SHARD_ATTESTER, slot_to_epoch(data.slot)) | ||
) | ||
``` | ||
|
||
|
@@ -328,7 +328,7 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock], | |
pubkey=beacon_state.validator_registry[proposer_index].pubkey, | ||
message_hash=signing_root(block), | ||
signature=candidate.signature, | ||
domain=get_domain(beacon_state, slot_to_epoch(candidate.slot), DOMAIN_SHARD_PROPOSER), | ||
domain=get_domain(beacon_state, DOMAIN_SHARD_PROPOSER, slot_to_epoch(candidate.slot)), | ||
) | ||
|
||
return True | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Workaround for
mypy
issue of redefining variable in the different scopes (python/mypy#5750).