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

Commit 49a2cf2

Browse files
committed
Propose with both attestation pools
1 parent df7e029 commit 49a2cf2

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

eth2/beacon/tools/builder/proposer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def create_block_on_state(
8282
parent_block=parent_block, block_params=FromBlockParams(slot=slot)
8383
)
8484

85+
# MAX_ATTESTATIONS
86+
attestations = attestations[: config.MAX_ATTESTATIONS]
87+
8588
# TODO: Add more operations
8689
randao_reveal = _generate_randao_reveal(privkey, slot, state, config)
8790
eth1_data = state.eth1_data

tests/components/eth2/beacon/test_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def get_validator(event_loop, event_bus, indices, num_validators=None) ->
8484
unaggregated_attestation_pool = set()
8585
aggregated_attestation_pool = set()
8686

87-
def get_ready_attestations_fn(slot):
87+
def get_ready_attestations_fn(slot, is_aggregated):
8888
return tuple(unaggregated_attestation_pool)
8989

9090
def get_aggregatable_attestations_fn(slot, committee_index):
@@ -458,7 +458,7 @@ async def test_validator_include_ready_attestations(event_loop, event_bus, monke
458458

459459
# Mock `get_ready_attestations_fn` so it returns the attestation alice
460460
# attested to.
461-
def get_ready_attestations_fn(slot):
461+
def get_ready_attestations_fn(slot, is_aggregated):
462462
return attestations
463463
monkeypatch.setattr(alice, 'get_ready_attestations', get_ready_attestations_fn)
464464

tests/libp2p/bcc/test_receive_server.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,21 +439,29 @@ def mock_get_head_state():
439439
state.slot = (
440440
attesting_slot + MINIMAL_SERENITY_CONFIG.MIN_ATTESTATION_INCLUSION_DELAY - 1
441441
)
442-
ready_attestations = receive_server.get_ready_attestations(state.slot)
442+
ready_attestations = receive_server.get_ready_attestations(
443+
state.slot, is_aggregated=False
444+
)
443445
assert len(ready_attestations) == 0
444446

445447
state.slot = (
446448
attesting_slot + MINIMAL_SERENITY_CONFIG.MIN_ATTESTATION_INCLUSION_DELAY
447449
)
448-
ready_attestations = receive_server.get_ready_attestations(state.slot)
450+
ready_attestations = receive_server.get_ready_attestations(
451+
state.slot, is_aggregated=False
452+
)
449453
assert set([a1, a2]) == set(ready_attestations)
450454

451455
state.slot = (
452456
attesting_slot + MINIMAL_SERENITY_CONFIG.MIN_ATTESTATION_INCLUSION_DELAY + 1
453457
)
454-
ready_attestations = receive_server.get_ready_attestations(state.slot)
458+
ready_attestations = receive_server.get_ready_attestations(
459+
state.slot, is_aggregated=False
460+
)
455461
assert set([a1, a2, a3]) == set(ready_attestations)
456462

457463
state.slot = attesting_slot + MINIMAL_SERENITY_CONFIG.SLOTS_PER_EPOCH + 1
458-
ready_attestations = receive_server.get_ready_attestations(state.slot)
464+
ready_attestations = receive_server.get_ready_attestations(
465+
state.slot, is_aggregated=False
466+
)
459467
assert set([a3]) == set(ready_attestations)

trinity/components/eth2/beacon/validator.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Callable,
66
Dict,
77
Iterable,
8-
Sequence,
98
Set,
109
Tuple,
1110
)
@@ -86,8 +85,8 @@
8685
from trinity.protocol.bcc_libp2p.configs import ATTESTATION_SUBNET_COUNT
8786

8887

89-
GetReadyAttestationsFn = Callable[[Slot], Sequence[Attestation]]
90-
GetAggregatableAttestationsFn = Callable[[Slot, CommitteeIndex], Sequence[Attestation]]
88+
GetReadyAttestationsFn = Callable[[Slot, bool], Tuple[Attestation, ...]]
89+
GetAggregatableAttestationsFn = Callable[[Slot, CommitteeIndex], Tuple[Attestation, ...]]
9190
ImportAttestationFn = Callable[[Attestation, bool], None]
9291

9392

@@ -263,7 +262,11 @@ async def propose_block(self,
263262
"""
264263
Propose a block and broadcast it.
265264
"""
266-
ready_attestations = self.get_ready_attestations(slot)
265+
# TODO(hwwhww): Check if need to aggregate and if they are overlapping.
266+
aggregated_attestations = self.get_ready_attestations(slot, True)
267+
unaggregated_attestations = self.get_ready_attestations(slot, False)
268+
ready_attestations = aggregated_attestations + unaggregated_attestations
269+
267270
block = create_block_on_state(
268271
state=state,
269272
config=state_machine.config,

trinity/protocol/bcc_libp2p/servers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,20 @@ def _is_block_seen(self, block: BaseBeaconBlock) -> bool:
366366
# Exposed APIs for Validator
367367
#
368368
@to_tuple
369-
def get_ready_attestations(self, current_slot: Slot) -> Iterable[Attestation]:
369+
def get_ready_attestations(
370+
self, current_slot: Slot, is_aggregated: bool
371+
) -> Iterable[Attestation]:
370372
"""
371373
Get the attestations that are ready to be included in ``current_slot`` block.
372374
"""
373375
config = self.chain.get_state_machine().config
374-
return self.unaggregated_attestation_pool.get_valid_attestation_by_current_slot(
376+
377+
if is_aggregated:
378+
attestation_pool = self.aggregated_attestation_pool
379+
else:
380+
attestation_pool = self.unaggregated_attestation_pool
381+
382+
return attestation_pool.get_valid_attestation_by_current_slot(
375383
current_slot,
376384
config,
377385
)

trinity/protocol/bcc_libp2p/topic_validators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def beacon_attestation_validator(msg_forwarder: ID, msg: rpc_pb2.Message) -> boo
8787
state_machine = chain.get_state_machine()
8888

8989
try:
90-
validate_beacon_block(chain, attestation)
90+
validate_voting_beacon_block(chain, attestation)
9191
validate_attestation_signature(
9292
state,
9393
attestation,
@@ -125,7 +125,7 @@ def committee_index_beacon_attestation_validator(
125125
try:
126126
validate_subnet_id(attestation, subnet_id)
127127
validate_is_unaggregated(attestation)
128-
validate_beacon_block(chain, attestation)
128+
validate_voting_beacon_block(chain, attestation)
129129
validate_attestation_propagation_slot_range(
130130
state,
131131
attestation,
@@ -163,7 +163,7 @@ def beacon_aggregate_and_proof_validator(msg_forwarder: ID, msg: rpc_pb2.Message
163163
attestation = aggregate_and_proof.aggregate
164164

165165
try:
166-
validate_beacon_block(chain, attestation)
166+
validate_voting_beacon_block(chain, attestation)
167167
run_validate_aggregate_and_proof(
168168
state,
169169
aggregate_and_proof,
@@ -229,7 +229,7 @@ def validate_is_unaggregated(attestation: Attestation) -> None:
229229
return False
230230

231231

232-
def validate_beacon_block(chain: BaseBeaconChain, attestation: Attestation) -> None:
232+
def validate_voting_beacon_block(chain: BaseBeaconChain, attestation: Attestation) -> None:
233233
# Check that beacon blocks attested to by the attestation are validated
234234
try:
235235
chain.get_block_by_root(attestation.data.beacon_block_root)

0 commit comments

Comments
 (0)