update some common usage of SSZ types, as a start

This commit is contained in:
protolambda 2019-05-25 00:10:06 +02:00
parent ed4416ba34
commit 81cb4a23b3
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
3 changed files with 27 additions and 45 deletions

View File

@ -33,9 +33,9 @@ Epoch = NewType('Epoch', int) # uint64
Shard = NewType('Shard', int) # uint64 Shard = NewType('Shard', int) # uint64
ValidatorIndex = NewType('ValidatorIndex', int) # uint64 ValidatorIndex = NewType('ValidatorIndex', int) # uint64
Gwei = NewType('Gwei', int) # uint64 Gwei = NewType('Gwei', int) # uint64
Bytes32 = NewType('Bytes32', bytes) # bytes32 Bytes32 = BytesN[32]
BLSPubkey = NewType('BLSPubkey', bytes) # bytes48 BLSPubkey = NewType('BLSPubkey', BytesN[48])
BLSSignature = NewType('BLSSignature', bytes) # bytes96 BLSSignature = NewType('BLSSignature', BytesN[96])
Store = None Store = None
""") """)

View File

@ -2,22 +2,6 @@ import sys
from typing import List from typing import List
def translate_ssz_type_line(line: str) -> str:
if ':' not in line:
return line
start = line[:line.index(':')]
field_type = line[line.index(':')+2:]
if field_type.startswith('['):
if ',' in line:
# TODO: translate [Foobar, SOME_THING] to Vector[Foobar, SSZLen(SOME_THING)] cleanly.
# just brute it here
field_type = 'Vector[%s, SSLen(%s)]' % (field_type[1:field_type.index(',')], field_type[field_type.index(',')+2:len(field_type)-1])
else:
field_type = 'List[%s]' % field_type[1:len(field_type)-1]
line = start + ': ' + field_type
return line
def get_spec(file_name: str) -> List[str]: def get_spec(file_name: str) -> List[str]:
code_lines = [] code_lines = []
pulling_from = None pulling_from = None
@ -51,8 +35,6 @@ def get_spec(file_name: str) -> List[str]:
if line[:3] == 'def': if line[:3] == 'def':
code_lines.append('') code_lines.append('')
code_lines.append('') code_lines.append('')
if current_typedef is not None:
line = translate_ssz_type_line(line)
code_lines.append(line) code_lines.append(line)
elif pulling_from is None and len(line) > 0 and line[0] == '|': elif pulling_from is None and len(line) > 0 and line[0] == '|':
row = line[1:].split('|') row = line[1:].split('|')

View File

@ -340,8 +340,8 @@ The types are defined topologically to aid in facilitating an executable version
```python ```python
{ {
# Validator indices # Validator indices
custody_bit_0_indices: [uint64] custody_bit_0_indices: List[uint64]
custody_bit_1_indices: [uint64] custody_bit_1_indices: List[uint64]
# Attestation data # Attestation data
data: AttestationData data: AttestationData
# Aggregate signature # Aggregate signature
@ -418,9 +418,9 @@ The types are defined topologically to aid in facilitating an executable version
```python ```python
{ {
# Block roots # Block roots
block_roots: [bytes32, SLOTS_PER_HISTORICAL_ROOT] block_roots: Vector[bytes32, SLOTS_PER_HISTORICAL_ROOT]
# State roots # State roots
state_roots: [bytes32, SLOTS_PER_HISTORICAL_ROOT] state_roots: Vector[bytes32, SLOTS_PER_HISTORICAL_ROOT]
} }
``` ```
@ -470,7 +470,7 @@ The types are defined topologically to aid in facilitating an executable version
```python ```python
{ {
# Branch in the deposit tree # Branch in the deposit tree
proof: [bytes32, DEPOSIT_CONTRACT_TREE_DEPTH] proof: Vector[bytes32, DEPOSIT_CONTRACT_TREE_DEPTH]
# Index in the deposit tree # Index in the deposit tree
index: uint64 index: uint64
# Data # Data
@ -521,12 +521,12 @@ The types are defined topologically to aid in facilitating an executable version
randao_reveal: bytes96 randao_reveal: bytes96
eth1_data: Eth1Data eth1_data: Eth1Data
graffiti: bytes32 graffiti: bytes32
proposer_slashings: [ProposerSlashing] proposer_slashings: List[ProposerSlashing]
attester_slashings: [AttesterSlashing] attester_slashings: List[AttesterSlashing]
attestations: [Attestation] attestations: List[Attestation]
deposits: [Deposit] deposits: List[Deposit]
voluntary_exits: [VoluntaryExit] voluntary_exits: List[VoluntaryExit]
transfers: [Transfer] transfers: List[Transfer]
} }
``` ```
@ -555,16 +555,16 @@ The types are defined topologically to aid in facilitating an executable version
fork: Fork # For versioning hard forks fork: Fork # For versioning hard forks
# Validator registry # Validator registry
validator_registry: [Validator] validator_registry: List[Validator]
balances: [uint64] balances: List[uint64]
# Randomness and committees # Randomness and committees
latest_randao_mixes: [bytes32, LATEST_RANDAO_MIXES_LENGTH] latest_randao_mixes: Vector[bytes32, LATEST_RANDAO_MIXES_LENGTH]
latest_start_shard: uint64 latest_start_shard: uint64
# Finality # Finality
previous_epoch_attestations: [PendingAttestation] previous_epoch_attestations: List[PendingAttestation]
current_epoch_attestations: [PendingAttestation] current_epoch_attestations: List[PendingAttestation]
previous_justified_epoch: uint64 previous_justified_epoch: uint64
current_justified_epoch: uint64 current_justified_epoch: uint64
previous_justified_root: bytes32 previous_justified_root: bytes32
@ -574,20 +574,20 @@ The types are defined topologically to aid in facilitating an executable version
finalized_root: bytes32 finalized_root: bytes32
# Recent state # Recent state
current_crosslinks: [Crosslink, SHARD_COUNT] current_crosslinks: Vector[Crosslink, SHARD_COUNT]
previous_crosslinks: [Crosslink, SHARD_COUNT] previous_crosslinks: Vector[Crosslink, SHARD_COUNT]
latest_block_roots: [bytes32, SLOTS_PER_HISTORICAL_ROOT] latest_block_roots: Vector[bytes32, SLOTS_PER_HISTORICAL_ROOT]
latest_state_roots: [bytes32, SLOTS_PER_HISTORICAL_ROOT] latest_state_roots: Vector[bytes32, SLOTS_PER_HISTORICAL_ROOT]
latest_active_index_roots: [bytes32, LATEST_ACTIVE_INDEX_ROOTS_LENGTH] latest_active_index_roots: Vector[bytes32, LATEST_ACTIVE_INDEX_ROOTS_LENGTH]
# Balances slashed at every withdrawal period # Balances slashed at every withdrawal period
latest_slashed_balances: [uint64, LATEST_SLASHED_EXIT_LENGTH] latest_slashed_balances: Vector[uint64, LATEST_SLASHED_EXIT_LENGTH]
# `latest_block_header.state_root == ZERO_HASH` temporarily # `latest_block_header.state_root == ZERO_HASH` temporarily
latest_block_header: BeaconBlockHeader latest_block_header: BeaconBlockHeader
historical_roots: [bytes32] historical_roots: List[bytes32]
# Ethereum 1.0 chain data # Ethereum 1.0 chain data
latest_eth1_data: Eth1Data latest_eth1_data: Eth1Data
eth1_data_votes: [Eth1Data] eth1_data_votes: List[Eth1Data]
deposit_index: uint64 deposit_index: uint64
} }
``` ```