Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Nov 21, 2019
1 parent adbc6a1 commit af1061e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions eth2/beacon/tools/builder/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from eth2.beacon.types.aggregate_and_proof import AggregateAndProof
from eth2.beacon.types.attestations import Attestation
from eth2.beacon.types.states import BeaconState
from eth2.beacon.typing import CommitteeIndex, Slot
from eth2.beacon.typing import Bitfield, CommitteeIndex, Slot
from eth2.configs import CommitteeConfig

# TODO: TARGET_AGGREGATORS_PER_COMMITTEE is not in Eth2Config now.
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_aggregate_from_valid_committee_attestations(

return Attestation(
data=attestations[0].data,
aggregation_bits=aggregation_bits,
aggregation_bits=Bitfield(aggregation_bits),
signature=aggregate_signature,
)

Expand Down
12 changes: 10 additions & 2 deletions tests/components/eth2/beacon/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,22 @@ async def get_validator(event_loop, event_bus, indices) -> Validator:
for index in indices
}

def get_ready_attestations_fn(slot, committee_index):
def get_ready_attestations_fn(slot):
return ()

def get_aggregatable_attestations_fn(slot, committee_index):
return ()

def import_attestation_fn(attestation):
return ()

v = Validator(
chain=chain,
p2p_node=FakeNode(),
validator_privkeys=validator_privkeys,
get_ready_attestations_fn=get_ready_attestations_fn,
get_aggregatable_attestations_fn=get_aggregatable_attestations_fn,
import_attestation_fn=import_attestation_fn,
event_bus=event_bus,
)
asyncio.ensure_future(v.run(), loop=event_loop)
Expand Down Expand Up @@ -387,7 +395,7 @@ async def test_validator_include_ready_attestations(event_loop, event_bus, monke

# Mock `get_ready_attestations_fn` so it returns the attestation alice
# attested to.
def get_ready_attestations_fn(slot, committee_index):
def get_ready_attestations_fn(slot):
return attestations
monkeypatch.setattr(alice, 'get_ready_attestations', get_ready_attestations_fn)

Expand Down
8 changes: 3 additions & 5 deletions trinity/components/eth2/beacon/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Callable,
Dict,
Iterable,
Optional,
Sequence,
Tuple,
)
Expand Down Expand Up @@ -88,8 +87,8 @@
from trinity.protocol.bcc_libp2p.configs import ATTESTATION_SUBNET_COUNT


GetReadyAttestationsFn = Callable[[Slot, Optional[CommitteeIndex]], Sequence[Attestation]]
GetAggregatableAttestationsFn = Callable[[Slot, Optional[CommitteeIndex]], Sequence[Attestation]]
GetReadyAttestationsFn = Callable[[Slot], Sequence[Attestation]]
GetAggregatableAttestationsFn = Callable[[Slot, CommitteeIndex], Sequence[Attestation]]
ImportAttestationFn = Callable[[Attestation], None]


Expand Down Expand Up @@ -267,7 +266,7 @@ async def propose_block(self,
state: BeaconState,
state_machine: BaseBeaconStateMachine,
head_block: BaseBeaconBlock) -> BaseBeaconBlock:
ready_attestations = self.get_ready_attestations(slot, None)
ready_attestations = self.get_ready_attestations(slot)
block = self._make_proposing_block(
proposer_index=proposer_index,
slot=slot,
Expand Down Expand Up @@ -438,7 +437,6 @@ async def attest(self, slot: Slot) -> Tuple[Attestation, ...]:
#

async def create_and_broadcast_aggregate_and_proof(self, slot: Slot) -> None:
self.logger.error("In _create_and_broadcast_aggregate_and_proof...")
# Check the aggregators selection
# aggregate_and_proofs: Tuple[AggregateAndProof] = ()
state_machine = self.chain.get_state_machine()
Expand Down
7 changes: 1 addition & 6 deletions trinity/protocol/bcc_libp2p/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ def _is_block_seen(self, block: BaseBeaconBlock) -> bool:
@to_tuple
def get_ready_attestations(
self,
current_slot: Slot,
committee_index: Optional[CommitteeIndex] = None
current_slot: Slot
) -> Iterable[Attestation]:
config = self.chain.get_state_machine().config
for attestation in self.attestation_pool.get_all():
Expand All @@ -416,10 +415,6 @@ def get_ready_attestations(
config.SLOTS_PER_EPOCH,
config.MIN_ATTESTATION_INCLUSION_DELAY,
)
# Filter by committee_index
if committee_index is not None and committee_index != attestation.data.index:
continue

except ValidationError:
continue
else:
Expand Down
10 changes: 5 additions & 5 deletions trinity/protocol/bcc_libp2p/topic_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
validate_aggregator_proof,
)
from eth2.beacon.typing import Slot
from eth2.configs import CommitteeConfig
from eth2.configs import CommitteeConfig, Eth2Config

from libp2p.peer.id import ID
from libp2p.pubsub.pb import rpc_pb2
Expand Down Expand Up @@ -146,7 +146,7 @@ def beacon_attestation_validator(msg_forwarder: ID, msg: rpc_pb2.Message) -> boo
def validate_aggregate_and_proof(
state: BeaconState,
aggregate_and_proof: AggregateAndProof,
config: CommitteeConfig,
config: Eth2Config,
) -> None:
"""
Validate aggregate_and_proof
Expand All @@ -169,7 +169,7 @@ def validate_aggregate_and_proof(
state,
aggregate_and_proof.aggregate.data,
aggregate_and_proof.aggregate.aggregation_bits,
config,
CommitteeConfig(config),
)
if aggregate_and_proof.index not in attesting_indices:
raise ValidationError(
Expand All @@ -182,13 +182,13 @@ def validate_aggregate_and_proof(
aggregate_and_proof.aggregate.data.slot,
aggregate_and_proof.aggregate.data.index,
aggregate_and_proof.selection_proof,
config,
CommitteeConfig(config),
):
raise ValidationError(
f"The given validator {aggregate_and_proof.index} is not selected aggregator"
)

validate_aggregator_proof(state, aggregate_and_proof, config)
validate_aggregator_proof(state, aggregate_and_proof, CommitteeConfig(config))

validate_attestation(state, aggregate_and_proof.aggregate, config)

Expand Down

0 comments on commit af1061e

Please sign in to comment.