async def generate_eth_cap_enr_field( vm_config: Tuple[Tuple[BlockNumber, Type[VirtualMachineAPI]], ...], headerdb: BaseAsyncHeaderDB, ) -> Tuple[Literal[b'eth'], Tuple[bytes, bytes]]: head = await headerdb.coro_get_canonical_head() genesis_hash = await headerdb.coro_get_canonical_block_hash(GENESIS_BLOCK_NUMBER) fork_blocks = forkid.extract_fork_blocks(vm_config) our_forkid = forkid.make_forkid(genesis_hash, head.block_number, fork_blocks) return (b'eth', sedes.List([forkid.ForkID]).serialize([our_forkid]))
def _make_node_with_enr_and_forkid(genesis_hash, head, vm_config): fork_blocks = forkid.extract_fork_blocks(vm_config) node_forkid = forkid.make_forkid(genesis_hash, head, fork_blocks) ip = socket.inet_aton(IPAddressFactory.generate()) udp_port = 30304 enr = ENRFactory( custom_kv_pairs={ b'eth': sedes.List([forkid.ForkID]).serialize([node_forkid]), IP_V4_ADDRESS_ENR_KEY: ip, UDP_PORT_ENR_KEY: udp_port, TCP_PORT_ENR_KEY: udp_port, }) return Node(enr)
def _test_make_forkid(vm_config, genesis_hash, head, expected_forkid): fork_blocks = extract_fork_blocks(vm_config) forkid = make_forkid(genesis_hash, head, fork_blocks) assert forkid.hash == expected_forkid.hash assert forkid.next == expected_forkid.next