async def get_validator( event_loop, event_bus, monkeypatch, indices, num_validators=None, ) -> Validator: if num_validators is not None: chain = BeaconChainFactory(num_validators=num_validators) else: chain = BeaconChainFactory() validator_privkeys = { index: mk_key_pair_from_seed_index(index)[1] for index in indices } # Mock attestation pool unaggregated_attestation_pool = set() aggregated_attestation_pool = set() def get_ready_attestations_fn(slot, is_aggregated): return tuple(unaggregated_attestation_pool) def get_aggregatable_attestations_fn(slot, committee_index): return tuple(unaggregated_attestation_pool) def import_attestation_fn(attestation, is_aggregated): if is_aggregated: aggregated_attestation_pool.add(attestation) else: unaggregated_attestation_pool.add(attestation) 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, ) # Make requesting eth1 vote and deposit a stub async def _get_eth1_vote(slot, state, state_machine): return None monkeypatch.setattr(v, '_get_eth1_vote', _get_eth1_vote) async def _get_deposit_data(state, state_machine, eth1_vote): return None monkeypatch.setattr(v, '_get_deposit_data', _get_deposit_data) asyncio.ensure_future(v.run(), loop=event_loop) await v.events.started.wait() # yield to `validator._run` await asyncio.sleep(0) return v
def get_logs(self, block_number: BlockNumber) -> Tuple[DepositLog, ...]: block_hash = block_number.to_bytes(32, byteorder="big") logs: Tuple[DepositLog, ...] = tuple() if block_number < self.start_block_number: return logs elif block_number == self.start_block_number: logs = tuple( DepositLog( block_hash=Hash32(block_hash), pubkey=deposit.pubkey, withdrawal_credentials=deposit.withdrawal_credentials, signature=deposit.signature, amount=deposit.amount, ) for deposit in self.deposits) return logs else: amount: Gwei = Gwei(32 * GWEI_PER_ETH) for seed in range(self.num_deposits_per_block): # Multiply `block_number` by 10 to shift it one digit to the left so # the input to the function is generated deterministically but does not # conflict with blocks in the future. pubkey, privkey = mk_key_pair_from_seed_index(block_number * 10 + seed) withdrawal_credentials = Hash32(b'\x12' * 32) deposit_data_message = DepositMessage.create( pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount, ) signature = sign_proof_of_possession( deposit_message=deposit_data_message, privkey=privkey, ) logs = logs + (DepositLog( block_hash=Hash32(block_hash), pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, signature=signature, amount=amount, ), ) return logs
async def get_validator(event_loop, event_bus, indices) -> Validator: chain = BeaconChainFactory() validator_privkeys = { index: mk_key_pair_from_seed_index(index)[1] for index in indices } def get_ready_attestations_fn(slot): return () v = Validator( chain=chain, p2p_node=FakeNode(), validator_privkeys=validator_privkeys, get_ready_attestations_fn=get_ready_attestations_fn, event_bus=event_bus, ) asyncio.ensure_future(v.run(), loop=event_loop) await v.events.started.wait() # yield to `validator._run` await asyncio.sleep(0) return v