Skip to content

Commit f444d69

Browse files
authored
Unify structure with rest of ethereum repos (ethereum#2)
* Migrate consensus specs from a submodule to the pypi eth2specs * Move from install script to Makefile & add linting
1 parent 0db2d6a commit f444d69

12 files changed

+194
-104
lines changed

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
VENV_NAME?=venv
2+
VENV_ACTIVATE=. $(VENV_NAME)/bin/activate
3+
4+
help:
5+
@echo "Makefile help. Your options are:"
6+
@echo "clean - remove build and Python file artifacts"
7+
@echo "install - install basic dependencies with venv"
8+
@echo "venv_lint - check style with flake8 and mypy with venv"
9+
@echo "venv_test - run tests with venv"
10+
11+
clean:
12+
rm -rf $(VENV_NAME)
13+
rm -rf *.egg-info
14+
find . -name __pycache__ -exec rm -rf {} \;
15+
find . -name .mypy_cache -exec rm -rf {} \;
16+
17+
install:
18+
python3 -m venv $(VENV_NAME);
19+
$(VENV_ACTIVATE)
20+
${VENV_NAME}/bin/python -m pip install -r requirements.txt
21+
${VENV_NAME}/bin/python -m pip install .
22+
@touch $(VENV_NAME)/bin/activate
23+
24+
venv_activate:
25+
$(VENV_ACTIVATE)
26+
27+
venv_lint: venv_activate
28+
flake8 --config=flake8.ini ./src ./tests && mypy --config-file mypy.ini ./src ./tests
29+
30+
venv_test: venv_activate
31+
@echo "TODO: implement tests"
32+

consensus-specs

Submodule consensus-specs deleted from 58b291b

flake8.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length= 120

install.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

mypy.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[mypy]
2+
warn_unused_ignores = True
3+
ignore_missing_imports = True
4+
strict_optional = False
5+
check_untyped_defs = True
6+
disallow_incomplete_defs = True
7+
disallow_untyped_defs = True
8+
disallow_any_generics = True
9+
disallow_untyped_calls = True
10+
warn_redundant_casts = True
11+
warn_unused_configs = True
12+
strict_equality = True

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# execution requirements
2+
eth2spec==1.1.2
3+
4+
# dev requirements
5+
mypy
6+
flake8

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
from setuptools import setup, find_packages
3+
from setuptools import find_packages, setup
44

55
setup(name='dvspec',
66
version='0.1',

src/dvspec/consensus.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
from dvspec.eth_node_interface import (
2-
AttestationDuty, ProposerDuty,
3-
AttestationData, BeaconBlock,
2+
AttestationData,
3+
AttestationDuty,
4+
BeaconBlock,
5+
ProposerDuty,
46
vc_is_slashable_attestation_data,
5-
vc_is_slashable_block,
7+
vc_is_slashable_block
68
)
79

8-
910
"""
1011
Consensus Specification
1112
"""
1213

14+
1315
def consensus_is_valid_attestation_data(attestation_data: AttestationData, attestation_duty: AttestationDuty) -> bool:
1416
"""Determines if the given attestation is valid for the attestation duty.
1517
"""
1618
assert attestation_data.slot == attestation_duty.slot
1719
assert attestation_data.committee_index == attestation_duty.committee_index
1820
assert not vc_is_slashable_attestation_data(attestation_data, attestation_duty.pubkey)
21+
return True
22+
1923

2024
def consensus_on_attestation(attestation_duty: AttestationDuty) -> AttestationData:
2125
"""Consensus protocol between distributed validator nodes for attestation values.
@@ -25,12 +29,15 @@ def consensus_on_attestation(attestation_duty: AttestationDuty) -> AttestationDa
2529
"""
2630
pass
2731

32+
2833
def consensus_is_valid_block(block: BeaconBlock, proposer_duty: ProposerDuty) -> bool:
2934
"""Determines if the given block is valid for the proposer duty.
3035
"""
3136
assert block.slot == proposer_duty.slot
3237
# TODO: Assert correct block.proposer_index
3338
assert not vc_is_slashable_block(block, proposer_duty.pubkey)
39+
return True
40+
3441

3542
def consensus_on_block(proposer_duty: ProposerDuty) -> AttestationData:
3643
"""Consensus protocol between distributed validator nodes for block values.

src/dvspec/eth_node_interface.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
from typing import List
22
from eth2spec.phase0.mainnet import (
3-
Container, SignedBeaconBlock, uint64, Bytes32,
4-
BLSPubkey, BLSSignature,
5-
Slot, Epoch,
6-
ValidatorIndex, CommitteeIndex,
7-
AttestationData, Attestation,
8-
BeaconBlock, SignedBeaconBlock,
3+
Attestation,
4+
AttestationData,
5+
BeaconBlock,
6+
BLSPubkey,
7+
BLSSignature,
8+
Bytes32,
9+
CommitteeIndex,
10+
Container,
11+
Epoch,
12+
SignedBeaconBlock,
13+
Slot,
14+
uint64,
15+
ValidatorIndex,
916
)
1017

18+
1119
class AttestationDuty(Container):
1220
pubkey: BLSPubkey
1321
validator_index: ValidatorIndex
1422
committee_index: CommitteeIndex
1523
committee_length: uint64
1624
committees_at_slot: uint64
17-
validator_committee_index: ValidatorIndex # TODO: Is this the correct datatype?
25+
validator_committee_index: ValidatorIndex # TODO: Is this the correct datatype?
1826
slot: Slot
19-
validator_index: ValidatorIndex
27+
2028

2129
class ProposerDuty(Container):
2230
pubkey: BLSPubkey
@@ -34,30 +42,35 @@ def bn_get_attestation_duties_for_epoch(validator_indices: List[ValidatorIndex],
3442
"""
3543
pass
3644

45+
3746
def bn_get_attestation_data(slot: Slot, committee_index: CommitteeIndex) -> AttestationData:
3847
"""Produces attestation data for the given slot & committee index.
3948
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/produceAttestationData
4049
"""
4150
pass
4251

52+
4353
def bn_submit_attestation(attestation: Attestation) -> None:
4454
"""Submit attestation to BN for Ethereum p2p gossip.
4555
Uses https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolAttestations
4656
"""
4757
pass
4858

59+
4960
def bn_get_proposer_duties_for_epoch(epoch: Epoch) -> List[ProposerDuty]:
5061
"""Fetch proposer duties for all proposers in the epoch.
5162
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/getProposerDuties
5263
"""
5364
pass
5465

66+
5567
def bn_produce_block(slot: Slot, randao_reveal: BLSSignature, graffiti: Bytes32) -> BeaconBlock:
5668
"""Produces valid block for given slot using provided data
5769
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/produceBlockV2
5870
"""
5971
pass
6072

73+
6174
def bn_submit_block(block: SignedBeaconBlock) -> None:
6275
"""Submit block to BN for Ethereum p2p gossip.
6376
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlock
@@ -73,20 +86,23 @@ def vc_is_slashable_attestation_data(attestation_data: AttestationData, validato
7386
"""
7487
pass
7588

89+
7690
def vc_sign_attestation(attestation_data: AttestationData, attestation_duty: AttestationDuty) -> Attestation:
7791
"""Returns a signed attestations that is constructed using the given attestation data & attestation duty.
7892
This endpoint does not exist in beacon-APIs.
7993
"""
80-
# See note about attestation construction here:
94+
# See note about attestation construction here:
8195
# https://github.com/ethereum/beacon-APIs/blame/05c1bc142e1a3fb2a63c79098743776241341d08/validator-flow.md#L35-L37
8296
pass
8397

98+
8499
def vc_is_slashable_block(block: BeaconBlock, validator_pubkey: BLSPubkey) -> bool:
85100
"""Checks whether the block is slashable according to the anti-slashing database.
86101
This endpoint does not exist in beacon-APIs.
87102
"""
88103
pass
89104

105+
90106
def vc_sign_block(block: BeaconBlock, proposer_duty: ProposerDuty) -> SignedBeaconBlock:
91107
"""Returns a signed beacon block using the validator index given in the proposer duty.
92108
This endpoint does not exist in beacon-APIs.

src/dvspec/networking.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
from typing import List
2-
from eth2spec.phase0.mainnet import (
3-
Attestation,
4-
SignedBeaconBlock,
5-
)
2+
3+
from eth2spec.phase0.mainnet import Attestation, SignedBeaconBlock
64

75
"""
86
Networking Specification
97
"""
108

9+
1110
def broadcast_threshold_signed_attestation(threshold_signed_attestation: Attestation) -> None:
1211
"""Broadcasts a threshold signed attestation among DV peer nodes.
1312
"""
1413
pass
1514

15+
1616
def listen_for_threshold_signed_attestations() -> List[Attestation]:
1717
"""Returns a list of any threshold signed attestations that can be combined to construct
1818
a complete signed attestation.
1919
"""
2020
pass
2121

22+
2223
def construct_signed_attestation(threshold_signed_attestations: List[Attestation]) -> Attestation:
2324
"""Broadcasts a threshold signed attestation among DV peer nodes.
2425
"""
2526
pass
2627

28+
2729
def broadcast_threshold_signed_block(threshold_signed_block: SignedBeaconBlock) -> None:
2830
"""Broadcasts a threshold signed beacon block among DV peer nodes.
2931
"""
3032
pass
3133

34+
3235
def listen_for_threshold_signed_blocks() -> List[SignedBeaconBlock]:
3336
"""Returns a list of any threshold signed blocks that can be combined to construct
3437
a complete signed block.
3538
"""
3639
pass
3740

41+
3842
def construct_signed_block(threshold_signed_blocks: List[SignedBeaconBlock]) -> SignedBeaconBlock:
3943
"""Broadcasts a threshold signed beacon block among DV peer nodes.
4044
"""

0 commit comments

Comments
 (0)