Fix some flake8 errors

This commit is contained in:
Hsiao-Wei Wang 2019-08-24 02:44:22 +08:00
parent 72b9781051
commit bcdbf7dfc7
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
1 changed files with 26 additions and 27 deletions

View File

@ -6,43 +6,37 @@
- [Phase 1 miscellaneous beacon chain changes](#phase-1-miscellaneous-beacon-chain-changes) - [Phase 1 miscellaneous beacon chain changes](#phase-1-miscellaneous-beacon-chain-changes)
- [Table of contents](#table-of-contents) - [Table of contents](#table-of-contents)
- [Custom types](#custom-types)
- [Configuration](#configuration) - [Configuration](#configuration)
- [Classes](#classes) - [Containers](#containers)
- [CompactCommittee](#compactcommittee) - [`CompactCommittee`](#compactcommittee)
- [ShardReceiptProof](#shardreceiptproof) - [`ShardReceiptProof`](#shardreceiptproof)
- [Helpers](#helpers) - [Helper functions](#helper-functions)
- [pack_compact_validator](#pack_compact_validator) - [`pack_compact_validator`](#pack_compact_validator)
- [unpack_compact_validator](#unpack_compact_validator) - [`unpack_compact_validator`](#unpack_compact_validator)
- [committee_to_compact_committee](#committee_to_compact_committee) - [`committee_to_compact_committee`](#committee_to_compact_committee)
- [get_previous_power_of_2](#get_previous_power_of_2) - [`get_previous_power_of_2`](#get_previous_power_of_2)
- [verify_merkle_proof](#verify_merkle_proof) - [`verify_merkle_proof`](#verify_merkle_proof)
- [concat_generalized_indices](#concat_generalized_indices) - [`compute_historical_state_generalized_index`](#compute_historical_state_generalized_index)
- [compute_historical_state_generalized_index](#compute_historical_state_generalized_index) - [`get_generalized_index_of_crosslink_header`](#get_generalized_index_of_crosslink_header)
- [get_generalized_index_of_crosslink_header](#get_generalized_index_of_crosslink_header) - [`process_shard_receipt_proof`](#process_shard_receipt_proof)
- [process_shard_receipt_proof](#process_shard_receipt_proof)
- [Changes](#changes) - [Changes](#changes)
- [Phase 0 container updates](#phase-0-container-updates)
- [`BeaconState`](#beaconstate)
- [`BeaconBlockBody`](#beaconblockbody)
- [Persistent committees](#persistent-committees) - [Persistent committees](#persistent-committees)
- [Shard receipt processing](#shard-receipt-processing) - [Shard receipt processing](#shard-receipt-processing)
<!-- /TOC --> <!-- /TOC -->
## Custom types
We define the following Python custom types for type hinting and readability:
| Name | SSZ equivalent | Description |
| - | - | - |
| `GeneralizedIndex` | `uint64` | a generalized index into an SSZ merkle tree |
## Configuration ## Configuration
| Name | Value | Unit | Duration | Name | Value | Unit | Duration
| - | - | - | - | | - | - | - | - |
| `MAX_SHARD_RECEIPT_PROOFS` | `2**0` (= 1) | - | - | | `MAX_SHARD_RECEIPT_PROOFS` | `2**0` (= 1) | - | - |
| `PERSISTENT_COMMITTEE_ROOT_LENGTH` | `2**8` (= 256) | periods | ~9 months | | `PERSISTENT_COMMITTEE_ROOT_LENGTH` | `2**8` (= 256) | periods | ~9 months |
| `MICRO_REWARD` | `Gwei(2**0)` (=1) | Gwei | - |
## Classes ## Containers
#### `CompactCommittee` #### `CompactCommittee`
@ -61,7 +55,7 @@ class ShardReceiptProof(Container):
receipt: List[ShardReceiptDelta, PLACEHOLDER] receipt: List[ShardReceiptDelta, PLACEHOLDER]
``` ```
## Helpers ## Helper functions
#### `pack_compact_validator` #### `pack_compact_validator`
@ -146,7 +140,9 @@ def get_generalized_index_of_crosslink_header(index: int) -> GeneralizedIndex:
""" """
Gets the generalized index for the root of the index'th header in a crosslink. Gets the generalized index for the root of the index'th header in a crosslink.
""" """
MAX_CROSSLINK_SIZE = SHARD_BLOCK_SIZE_LIMIT * SHARD_SLOTS_PER_BEACON_SLOT * SLOTS_PER_EPOCH * MAX_EPOCHS_PER_CROSSLINK MAX_CROSSLINK_SIZE = (
SHARD_BLOCK_SIZE_LIMIT * SHARD_SLOTS_PER_BEACON_SLOT * SLOTS_PER_EPOCH * MAX_EPOCHS_PER_CROSSLINK
)
assert MAX_CROSSLINK_SIZE == get_previous_power_of_2(MAX_CROSSLINK_SIZE) assert MAX_CROSSLINK_SIZE == get_previous_power_of_2(MAX_CROSSLINK_SIZE)
return GeneralizedIndex(MAX_CROSSLINK_SIZE // SHARD_HEADER_SIZE + index) return GeneralizedIndex(MAX_CROSSLINK_SIZE // SHARD_HEADER_SIZE + index)
``` ```
@ -170,11 +166,14 @@ def process_shard_receipt_proof(state: BeaconState, receipt_proof: ShardReceiptP
leaf=hash_tree_root(receipt_proof.receipt), leaf=hash_tree_root(receipt_proof.receipt),
proof=receipt_proof.proof, proof=receipt_proof.proof,
index=gindex, index=gindex,
root=state.current_crosslinks[shard].data_root root=state.current_crosslinks[receipt_proof.shard].data_root
) )
for delta in receipt_proof.receipt: for delta in receipt_proof.receipt:
if get_current_epoch(state) < state.validators[delta.index].withdrawable_epoch: if get_current_epoch(state) < state.validators[delta.index].withdrawable_epoch:
increase_balance(state, delta.index, state.validators[delta.index].effective_balance * delta.reward_coefficient // REWARD_COEFFICIENT_BASE) increase_amount = (
state.validators[delta.index].effective_balance * delta.reward_coefficient // REWARD_COEFFICIENT_BASE
)
increase_balance(state, delta.index, increase_amount)
decrease_balance(state, delta.index, delta.block_fee) decrease_balance(state, delta.index, delta.block_fee)
state.next_shard_receipt_period[receipt_proof.shard] += 1 state.next_shard_receipt_period[receipt_proof.shard] += 1
increase_balance(state, get_beacon_proposer_index(state), MICRO_REWARD) increase_balance(state, get_beacon_proposer_index(state), MICRO_REWARD)