Add `tpt_bind_addrs` param to `open_root_actor()`

Allow callers to explicitly declare transport
bind addrs instead of always auto-generating
random ones from ponged registrar addresses.

Deats,
- new `tpt_bind_addrs` kwarg wraps each input
  addr via `wrap_address()` at init time.
- non-registrar path only auto-generates random
  bind addrs when `tpt_bind_addrs` is empty.
- registrar path merges user-provided bind addrs
  with `uw_reg_addrs` via `set()` union.
- drop the deprecated `arbiter_addr` param and
  its `DeprecationWarning` shim entirely.

Also,
- expand `registry_addrs` type annotation to
  `Address|UnwrappedAddress`.
- replace bare `assert accept_addrs` in
  `async_main()` with a descriptive
  `RuntimeError` msg.

(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
subint_spawner_backend
Gud Boi 2026-04-13 13:33:09 -04:00
parent f881683c97
commit bc60aa1ec5
2 changed files with 44 additions and 31 deletions

View File

@ -145,11 +145,16 @@ async def maybe_block_bp(
@acm @acm
async def open_root_actor( async def open_root_actor(
*, *,
# defaults are above tpt_bind_addrs: list[
registry_addrs: list[UnwrappedAddress]|None = None, Address # `Address.get_random()` case
|UnwrappedAddress # registrar case `= uw_reg_addrs`
]|None = None,
# defaults are above # defaults are above
arbiter_addr: tuple[UnwrappedAddress]|None = None, registry_addrs: list[
Address
|UnwrappedAddress
]|None = None,
enable_transports: list[ enable_transports: list[
# TODO, this should eventually be the pairs as # TODO, this should eventually be the pairs as
@ -268,15 +273,7 @@ async def open_root_actor(
if start_method is not None: if start_method is not None:
_spawn.try_set_start_method(start_method) _spawn.try_set_start_method(start_method)
if arbiter_addr is not None: # XXX expect pre-unwrapped registrar addrs.
warnings.warn(
'`arbiter_addr` is now deprecated\n'
'Use `registry_addrs: list[tuple]` instead..',
DeprecationWarning,
stacklevel=2,
)
uw_reg_addrs = [arbiter_addr]
uw_reg_addrs = registry_addrs uw_reg_addrs = registry_addrs
if not uw_reg_addrs: if not uw_reg_addrs:
uw_reg_addrs: list[UnwrappedAddress] = default_lo_addrs( uw_reg_addrs: list[UnwrappedAddress] = default_lo_addrs(
@ -289,7 +286,6 @@ async def open_root_actor(
wrap_address(uw_addr) wrap_address(uw_addr)
for uw_addr in uw_reg_addrs for uw_addr in uw_reg_addrs
] ]
loglevel: str = ( loglevel: str = (
loglevel loglevel
or or
@ -386,10 +382,14 @@ async def open_root_actor(
addr, addr,
) )
tpt_bind_addrs: list[ if tpt_bind_addrs is None:
Address # `Address.get_random()` case tpt_bind_addrs: list[Address] = []
|UnwrappedAddress # registrar case `= uw_reg_addrs` else:
] = [] input_bind_addrs = list(tpt_bind_addrs)
tpt_bind_addrs: list[Address] = []
for addr in input_bind_addrs:
addr: Address = wrap_address(addr)
tpt_bind_addrs.append(addr)
# ------ NON-REGISTRAR ------ # ------ NON-REGISTRAR ------
# create a new root-actor instance. # create a new root-actor instance.
@ -417,19 +417,20 @@ async def open_root_actor(
# a new NON-registrar, ROOT-actor. # a new NON-registrar, ROOT-actor.
# #
# XXX INSTEAD, bind random addrs using the same tpt # XXX INSTEAD, bind random addrs using the same tpt
# proto. # proto if not already provided.
for addr in ponged_addrs: if not tpt_bind_addrs:
tpt_bind_addrs.append( for addr in ponged_addrs:
# XXX, these are `Address` NOT `UnwrappedAddress`. tpt_bind_addrs.append(
# # XXX, these are `Address` NOT `UnwrappedAddress`.
# NOTE, in the case of posix/berkley socket #
# protos we allocate port=0 such that the system # NOTE, in the case of posix/berkley socket
# allocates a random value at bind time; this # protos we allocate port=0 such that the system
# happens in the `.ipc.*` stack's backend. # allocates a random value at bind time; this
addr.get_random( # happens in the `.ipc.*` stack's backend.
bindspace=addr.bindspace, addr.get_random(
bindspace=addr.bindspace,
)
) )
)
# ------ REGISTRAR ------ # ------ REGISTRAR ------
# create a new "registry providing" root-actor instance. # create a new "registry providing" root-actor instance.
@ -442,7 +443,11 @@ async def open_root_actor(
# following init steps are taken: # following init steps are taken:
# - the tranport layer server is bound to each addr # - the tranport layer server is bound to each addr
# pair defined in provided registry_addrs, or the default. # pair defined in provided registry_addrs, or the default.
tpt_bind_addrs = uw_reg_addrs tpt_bind_addrs = list(set(
tpt_bind_addrs
+
uw_reg_addrs
))
# - it is normally desirable for any registrar to stay up # - it is normally desirable for any registrar to stay up
# indefinitely until either all registered (child/sub) # indefinitely until either all registered (child/sub)

View File

@ -1564,7 +1564,15 @@ async def async_main(
addr: Address = transport_cls.get_random() addr: Address = transport_cls.get_random()
accept_addrs.append(addr.unwrap()) accept_addrs.append(addr.unwrap())
assert accept_addrs # XXX, either passed in by caller or delivered
# in post spawn-spec handshake for subs.
if not accept_addrs:
RuntimeError(
f'No tpt bind addresses provided to actor!?\n'
f'parent_addr={parent_addr!r}\n'
f'accept_addrs={accept_addrs!r}\n'
f'enable_transports={enable_transports!r}\n'
)
ya_root_tn: bool = bool(actor._root_tn) ya_root_tn: bool = bool(actor._root_tn)
ya_service_tn: bool = bool(actor._service_tn) ya_service_tn: bool = bool(actor._service_tn)